@positronic/core 0.0.77 → 0.0.78

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 (130) hide show
  1. package/dist/src/dsl/brain-runner.js +37 -182
  2. package/dist/src/dsl/brain-state-machine.js +58 -112
  3. package/dist/src/dsl/brain.js +1 -0
  4. package/dist/src/dsl/builder/brain.js +250 -412
  5. package/dist/src/dsl/builder/continuation.js +67 -0
  6. package/dist/src/dsl/constants.js +16 -17
  7. package/dist/src/dsl/create-brain.js +29 -45
  8. package/dist/src/dsl/example-webhook.js +1 -1
  9. package/dist/src/dsl/execution/constants.js +0 -4
  10. package/dist/src/dsl/execution/event-channel.js +77 -0
  11. package/dist/src/dsl/execution/event-stream.js +1625 -1474
  12. package/dist/src/dsl/signal-validation.js +0 -1
  13. package/dist/src/dsl/webhook.js +4 -1
  14. package/dist/src/files/event-wrapper.js +268 -0
  15. package/dist/src/files/index.js +1 -0
  16. package/dist/src/files/mime.js +31 -0
  17. package/dist/src/files/types.js +13 -0
  18. package/dist/src/index.js +10 -3
  19. package/dist/src/jsx-runtime.js +49 -0
  20. package/dist/src/memory/{scoped-memory.js → create-memory.js} +5 -5
  21. package/dist/src/plugins/collect-webhooks.js +49 -0
  22. package/dist/src/plugins/define-plugin.js +15 -0
  23. package/dist/src/plugins/index.js +1 -0
  24. package/dist/src/plugins/types.js +4 -0
  25. package/dist/src/store/types.js +2 -3
  26. package/dist/src/template/render-html.js +282 -0
  27. package/dist/src/template/render.js +357 -0
  28. package/dist/src/tools/index.js +88 -27
  29. package/dist/src/ui/generate-page-html.js +6 -6
  30. package/dist/src/ui/{generate-ui.js → generate-page.js} +24 -12
  31. package/dist/src/ui/parse-form-data.js +1 -11
  32. package/dist/src/ui/types.js +0 -123
  33. package/dist/src/yaml/data-validator.js +0 -27
  34. package/dist/src/yaml/type-inference.js +10 -9
  35. package/dist/types/clients/types.d.ts +15 -5
  36. package/dist/types/clients/types.d.ts.map +1 -1
  37. package/dist/types/dsl/brain-runner.d.ts +9 -14
  38. package/dist/types/dsl/brain-runner.d.ts.map +1 -1
  39. package/dist/types/dsl/brain-state-machine.d.ts +18 -28
  40. package/dist/types/dsl/brain-state-machine.d.ts.map +1 -1
  41. package/dist/types/dsl/brain.d.ts +3 -2
  42. package/dist/types/dsl/brain.d.ts.map +1 -1
  43. package/dist/types/dsl/builder/brain.d.ts +85 -228
  44. package/dist/types/dsl/builder/brain.d.ts.map +1 -1
  45. package/dist/types/dsl/builder/continuation.d.ts +16 -0
  46. package/dist/types/dsl/builder/continuation.d.ts.map +1 -0
  47. package/dist/types/dsl/constants.d.ts +12 -12
  48. package/dist/types/dsl/constants.d.ts.map +1 -1
  49. package/dist/types/dsl/create-brain.d.ts +17 -57
  50. package/dist/types/dsl/create-brain.d.ts.map +1 -1
  51. package/dist/types/dsl/definitions/blocks.d.ts +67 -66
  52. package/dist/types/dsl/definitions/blocks.d.ts.map +1 -1
  53. package/dist/types/dsl/definitions/brain-types.d.ts +8 -11
  54. package/dist/types/dsl/definitions/brain-types.d.ts.map +1 -1
  55. package/dist/types/dsl/definitions/events.d.ts +61 -56
  56. package/dist/types/dsl/definitions/events.d.ts.map +1 -1
  57. package/dist/types/dsl/definitions/run-params.d.ts +20 -21
  58. package/dist/types/dsl/definitions/run-params.d.ts.map +1 -1
  59. package/dist/types/dsl/definitions/steps.d.ts +1 -1
  60. package/dist/types/dsl/definitions/steps.d.ts.map +1 -1
  61. package/dist/types/dsl/example-webhook.d.ts +3 -3
  62. package/dist/types/dsl/example-webhook.d.ts.map +1 -1
  63. package/dist/types/dsl/execution/constants.d.ts +0 -5
  64. package/dist/types/dsl/execution/constants.d.ts.map +1 -1
  65. package/dist/types/dsl/execution/event-channel.d.ts +16 -0
  66. package/dist/types/dsl/execution/event-channel.d.ts.map +1 -0
  67. package/dist/types/dsl/execution/event-stream.d.ts +46 -34
  68. package/dist/types/dsl/execution/event-stream.d.ts.map +1 -1
  69. package/dist/types/dsl/signal-validation.d.ts.map +1 -1
  70. package/dist/types/dsl/types.d.ts +21 -83
  71. package/dist/types/dsl/types.d.ts.map +1 -1
  72. package/dist/types/dsl/webhook.d.ts +12 -2
  73. package/dist/types/dsl/webhook.d.ts.map +1 -1
  74. package/dist/types/files/event-wrapper.d.ts +20 -0
  75. package/dist/types/files/event-wrapper.d.ts.map +1 -0
  76. package/dist/types/files/index.d.ts +2 -0
  77. package/dist/types/files/index.d.ts.map +1 -0
  78. package/dist/types/files/mime.d.ts +2 -0
  79. package/dist/types/files/mime.d.ts.map +1 -0
  80. package/dist/types/files/types.d.ts +88 -0
  81. package/dist/types/files/types.d.ts.map +1 -0
  82. package/dist/types/index.d.ts +22 -13
  83. package/dist/types/index.d.ts.map +1 -1
  84. package/dist/types/jsx-runtime.d.ts +35 -0
  85. package/dist/types/jsx-runtime.d.ts.map +1 -0
  86. package/dist/types/memory/{scoped-memory.d.ts → create-memory.d.ts} +7 -7
  87. package/dist/types/memory/create-memory.d.ts.map +1 -0
  88. package/dist/types/memory/types.d.ts +4 -4
  89. package/dist/types/memory/types.d.ts.map +1 -1
  90. package/dist/types/plugins/collect-webhooks.d.ts +8 -0
  91. package/dist/types/plugins/collect-webhooks.d.ts.map +1 -0
  92. package/dist/types/plugins/define-plugin.d.ts +25 -0
  93. package/dist/types/plugins/define-plugin.d.ts.map +1 -0
  94. package/dist/types/plugins/index.d.ts +3 -0
  95. package/dist/types/plugins/index.d.ts.map +1 -0
  96. package/dist/types/plugins/types.d.ts +83 -0
  97. package/dist/types/plugins/types.d.ts.map +1 -0
  98. package/dist/types/store/index.d.ts +1 -1
  99. package/dist/types/store/index.d.ts.map +1 -1
  100. package/dist/types/store/types.d.ts +0 -8
  101. package/dist/types/store/types.d.ts.map +1 -1
  102. package/dist/types/template/render-html.d.ts +9 -0
  103. package/dist/types/template/render-html.d.ts.map +1 -0
  104. package/dist/types/template/render.d.ts +15 -0
  105. package/dist/types/template/render.d.ts.map +1 -0
  106. package/dist/types/tools/index.d.ts +39 -27
  107. package/dist/types/tools/index.d.ts.map +1 -1
  108. package/dist/types/ui/generate-page-html.d.ts +4 -6
  109. package/dist/types/ui/generate-page-html.d.ts.map +1 -1
  110. package/dist/types/ui/{generate-ui.d.ts → generate-page.d.ts} +6 -6
  111. package/dist/types/ui/generate-page.d.ts.map +1 -0
  112. package/dist/types/ui/parse-form-data.d.ts +1 -5
  113. package/dist/types/ui/parse-form-data.d.ts.map +1 -1
  114. package/dist/types/ui/types.d.ts +0 -49
  115. package/dist/types/ui/types.d.ts.map +1 -1
  116. package/dist/types/yaml/data-validator.d.ts +0 -5
  117. package/dist/types/yaml/data-validator.d.ts.map +1 -1
  118. package/dist/types/yaml/type-inference.d.ts +4 -2
  119. package/dist/types/yaml/type-inference.d.ts.map +1 -1
  120. package/dist/types/yaml/types.d.ts +0 -1
  121. package/dist/types/yaml/types.d.ts.map +1 -1
  122. package/package.json +5 -1
  123. package/dist/src/dsl/agent-messages.js +0 -5
  124. package/dist/src/ui/validate-form.js +0 -428
  125. package/dist/types/dsl/agent-messages.d.ts +0 -12
  126. package/dist/types/dsl/agent-messages.d.ts.map +0 -1
  127. package/dist/types/memory/scoped-memory.d.ts.map +0 -1
  128. package/dist/types/ui/generate-ui.d.ts.map +0 -1
  129. package/dist/types/ui/validate-form.d.ts +0 -45
  130. package/dist/types/ui/validate-form.d.ts.map +0 -1
@@ -0,0 +1,67 @@
1
+ function _class_call_check(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
+ }
6
+ function _defineProperties(target, props) {
7
+ for(var i = 0; i < props.length; i++){
8
+ var descriptor = props[i];
9
+ descriptor.enumerable = descriptor.enumerable || false;
10
+ descriptor.configurable = true;
11
+ if ("value" in descriptor) descriptor.writable = true;
12
+ Object.defineProperty(target, descriptor.key, descriptor);
13
+ }
14
+ }
15
+ function _create_class(Constructor, protoProps, staticProps) {
16
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
+ if (staticProps) _defineProperties(Constructor, staticProps);
18
+ return Constructor;
19
+ }
20
+ function _define_property(obj, key, value) {
21
+ if (key in obj) {
22
+ Object.defineProperty(obj, key, {
23
+ value: value,
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true
27
+ });
28
+ } else {
29
+ obj[key] = value;
30
+ }
31
+ return obj;
32
+ }
33
+ export var Continuation = /*#__PURE__*/ function() {
34
+ "use strict";
35
+ function Continuation(addBlock, createNextBrain) {
36
+ _class_call_check(this, Continuation);
37
+ _define_property(this, "addBlock", void 0);
38
+ _define_property(this, "createNextBrain", void 0);
39
+ this.addBlock = addBlock;
40
+ this.createNextBrain = createNextBrain;
41
+ }
42
+ _create_class(Continuation, [
43
+ {
44
+ key: "handle",
45
+ value: function handle(title, action) {
46
+ this.addBlock({
47
+ type: 'step',
48
+ title: title,
49
+ action: action
50
+ });
51
+ return this.createNextBrain();
52
+ }
53
+ },
54
+ {
55
+ key: "guard",
56
+ value: function guard(predicate, title) {
57
+ this.addBlock({
58
+ type: 'guard',
59
+ title: title !== null && title !== void 0 ? title : 'Guard',
60
+ predicate: predicate
61
+ });
62
+ return new Continuation(this.addBlock, this.createNextBrain);
63
+ }
64
+ }
65
+ ]);
66
+ return Continuation;
67
+ }();
@@ -13,20 +13,22 @@ export var BRAIN_EVENTS = {
13
13
  RESUMED: 'brain:resumed',
14
14
  WEBHOOK: 'brain:webhook',
15
15
  WEBHOOK_RESPONSE: 'brain:webhook_response',
16
- // Agent step events
17
- AGENT_START: 'agent:start',
18
- AGENT_ITERATION: 'agent:iteration',
19
- AGENT_TOOL_CALL: 'agent:tool_call',
20
- AGENT_TOOL_RESULT: 'agent:tool_result',
21
- AGENT_ASSISTANT_MESSAGE: 'agent:assistant_message',
22
- AGENT_COMPLETE: 'agent:complete',
23
- AGENT_TOKEN_LIMIT: 'agent:token_limit',
24
- AGENT_ITERATION_LIMIT: 'agent:iteration_limit',
25
- AGENT_WEBHOOK: 'agent:webhook',
26
- AGENT_RAW_RESPONSE_MESSAGE: 'agent:raw_response_message',
27
- AGENT_USER_MESSAGE: 'agent:user_message',
28
16
  // Iterate events (prompt/brain with `over`)
29
- ITERATE_ITEM_COMPLETE: 'iterate:item_complete'
17
+ ITERATE_ITEM_COMPLETE: 'iterate:item_complete',
18
+ // Prompt loop events
19
+ PROMPT_START: 'prompt:start',
20
+ PROMPT_ITERATION: 'prompt:iteration',
21
+ PROMPT_TOOL_CALL: 'prompt:tool_call',
22
+ PROMPT_TOOL_RESULT: 'prompt:tool_result',
23
+ PROMPT_ASSISTANT_MESSAGE: 'prompt:assistant_message',
24
+ PROMPT_COMPLETE: 'prompt:complete',
25
+ PROMPT_TOKEN_LIMIT: 'prompt:token_limit',
26
+ PROMPT_ITERATION_LIMIT: 'prompt:iteration_limit',
27
+ PROMPT_RAW_RESPONSE_MESSAGE: 'prompt:raw_response_message',
28
+ PROMPT_WEBHOOK: 'prompt:webhook',
29
+ // File events
30
+ FILE_WRITE_START: 'file:write_start',
31
+ FILE_WRITE_COMPLETE: 'file:write_complete'
30
32
  };
31
33
  export var STATUS = {
32
34
  PENDING: 'pending',
@@ -36,8 +38,5 @@ export var STATUS = {
36
38
  CANCELLED: 'cancelled',
37
39
  WAITING: 'waiting',
38
40
  PAUSED: 'paused',
39
- HALTED: 'halted',
40
- // Internal status for tracking when execution is inside an agent loop.
41
- // Publicly this maps to RUNNING for consumers.
42
- AGENT_LOOP: 'agent_loop'
41
+ HALTED: 'halted'
43
42
  };
@@ -1,69 +1,53 @@
1
1
  import { brain as coreBrain } from './builder/brain.js';
2
2
  /**
3
- * Creates a project-level brain function with pre-configured services, components, and tools.
3
+ * Creates a project-level brain function with pre-configured plugins and components.
4
4
  *
5
- * This is the recommended way to set up brains in a Positronic project. It provides:
6
- * - Type-safe access to services in all brain steps
7
- * - Automatic injection of components and default tools
8
- * - Support for both builder pattern and direct agent creation
5
+ * Plugin types are inferred from the array and propagated to all brains
6
+ * created by the returned factory function.
9
7
  *
10
8
  * @example
11
9
  * ```typescript
12
- * // brain.ts - your project's brain configuration
13
10
  * import { createBrain } from '@positronic/core';
11
+ * import { mem0 } from '@positronic/mem0';
14
12
  * import { components } from './components/index.js';
15
- * import slack from './services/slack.js';
16
- * import gmail from './services/gmail.js';
17
13
  *
18
14
  * export const brain = createBrain({
19
- * services: { slack, gmail },
15
+ * plugins: [mem0.setup({ provider })],
20
16
  * components,
21
17
  * });
22
18
  * ```
23
- *
24
- * @example
25
- * ```typescript
26
- * // brains/my-brain.ts - using the configured brain
27
- * import { brain } from '../brain.js';
28
- *
29
- * // Builder pattern
30
- * export default brain('my-workflow')
31
- * .step('Init', ({ slack }) => {
32
- * slack.postMessage('#general', 'Starting workflow');
33
- * return { started: true };
34
- * });
35
- *
36
- * // Or direct agent creation
37
- * export default brain('my-agent', ({ slack, env }) => ({
38
- * system: 'You are helpful',
39
- * prompt: 'Help the user',
40
- * tools: { ... }
41
- * }));
42
- * ```
43
19
  */ export function createBrain(config) {
44
- var services = config.services, components = config.components, defaultTools = config.defaultTools, memory = config.memory, store = config.store;
20
+ var plugins = config.plugins, components = config.components;
45
21
  // Implementation
46
- function brain(titleOrConfig, agentConfig) {
22
+ function brain(titleOrConfig) {
47
23
  var base = coreBrain(titleOrConfig);
48
24
  if (components) {
49
25
  base = base.withComponents(components);
50
26
  }
51
- if (defaultTools) {
52
- base = base.withTools(defaultTools);
53
- }
54
- if (memory) {
55
- base = base.withMemory(memory);
56
- }
57
- if (store) {
58
- base = base.withStore(store);
59
- }
60
- if (services) {
61
- base = base.withServices(services);
62
- }
63
- if (agentConfig) {
64
- return base.brain('main', agentConfig);
27
+ if (plugins) {
28
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
29
+ try {
30
+ for(var _iterator = plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
31
+ var plugin = _step.value;
32
+ base = base.withPlugin(plugin);
33
+ }
34
+ } catch (err) {
35
+ _didIteratorError = true;
36
+ _iteratorError = err;
37
+ } finally{
38
+ try {
39
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
40
+ _iterator.return();
41
+ }
42
+ } finally{
43
+ if (_didIteratorError) {
44
+ throw _iteratorError;
45
+ }
46
+ }
47
+ }
65
48
  }
66
49
  return base;
67
50
  }
51
+ brain.plugins = plugins !== null && plugins !== void 0 ? plugins : [];
68
52
  return brain;
69
53
  }
@@ -248,7 +248,7 @@ var myBrain = brain('My Brain').step('My Step', function(param) {
248
248
  ];
249
249
  }, {
250
250
  timeout: '24h'
251
- }).step('My Step 2', function(param) {
251
+ }).handle('My Step 2', function(param) {
252
252
  var state = param.state, response = param.response;
253
253
  if (response) {
254
254
  if ('threadId' in response) {
@@ -5,7 +5,3 @@
5
5
  origin: 'http://localhost:8787',
6
6
  secrets: {}
7
7
  };
8
- /**
9
- * Default system prompt prepended to all agent steps.
10
- * Explains the headless nature of Positronic Brains.
11
- */ export var DEFAULT_AGENT_SYSTEM_PROMPT = "## You Are a Positronic Brain\n\nYou are running as an automated agent in a headless workflow. This is NOT a chat interface - there is no user watching your text output.\n\n**To communicate with users, you MUST use tool calls.** Look at your available tools and use them to send messages, notifications, or create pages for user interaction.\n\n## Tool Execution\n- Tools execute sequentially in the order you call them\n- Webhook-triggering tools pause execution until the webhook fires\n- Terminal tools (like 'done') end the agent immediately\n\n## Resumption\nWhen resuming after a webhook, that response appears as the tool result in your conversation history.";
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Simple async queue for passing events between a service (producer)
3
+ * and the event stream (consumer) during step execution.
4
+ *
5
+ * The event stream uses Promise.race between the step completing and
6
+ * channel.wait() to yield events mid-step without blocking.
7
+ */ function _class_call_check(instance, Constructor) {
8
+ if (!(instance instanceof Constructor)) {
9
+ throw new TypeError("Cannot call a class as a function");
10
+ }
11
+ }
12
+ function _defineProperties(target, props) {
13
+ for(var i = 0; i < props.length; i++){
14
+ var descriptor = props[i];
15
+ descriptor.enumerable = descriptor.enumerable || false;
16
+ descriptor.configurable = true;
17
+ if ("value" in descriptor) descriptor.writable = true;
18
+ Object.defineProperty(target, descriptor.key, descriptor);
19
+ }
20
+ }
21
+ function _create_class(Constructor, protoProps, staticProps) {
22
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
23
+ if (staticProps) _defineProperties(Constructor, staticProps);
24
+ return Constructor;
25
+ }
26
+ function _define_property(obj, key, value) {
27
+ if (key in obj) {
28
+ Object.defineProperty(obj, key, {
29
+ value: value,
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true
33
+ });
34
+ } else {
35
+ obj[key] = value;
36
+ }
37
+ return obj;
38
+ }
39
+ export var EventChannel = /*#__PURE__*/ function() {
40
+ "use strict";
41
+ function EventChannel() {
42
+ _class_call_check(this, EventChannel);
43
+ _define_property(this, "queue", []);
44
+ _define_property(this, "waiter", null);
45
+ }
46
+ _create_class(EventChannel, [
47
+ {
48
+ key: "push",
49
+ value: function push(item) {
50
+ this.queue.push(item);
51
+ if (this.waiter) {
52
+ this.waiter();
53
+ this.waiter = null;
54
+ }
55
+ }
56
+ },
57
+ {
58
+ /** Resolves when at least one item is in the queue, or immediately if non-empty */ key: "wait",
59
+ value: function wait() {
60
+ var _this = this;
61
+ if (this.queue.length > 0) return Promise.resolve();
62
+ return new Promise(function(resolve) {
63
+ _this.waiter = resolve;
64
+ });
65
+ }
66
+ },
67
+ {
68
+ key: "drain",
69
+ value: function drain() {
70
+ var items = this.queue;
71
+ this.queue = [];
72
+ return items;
73
+ }
74
+ }
75
+ ]);
76
+ return EventChannel;
77
+ }();