@positronic/core 0.0.52 → 0.0.53

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 (96) hide show
  1. package/dist/src/dsl/{loop-messages.js → agent-messages.js} +21 -21
  2. package/dist/src/dsl/brain-runner.js +6 -6
  3. package/dist/src/dsl/brain-state-machine.js +2 -2
  4. package/dist/src/dsl/brain.js +5 -1912
  5. package/dist/src/dsl/builder/brain.js +944 -0
  6. package/dist/src/dsl/builder/step.js +75 -0
  7. package/dist/src/dsl/constants.js +9 -10
  8. package/dist/src/dsl/create-brain.js +63 -0
  9. package/dist/src/dsl/definitions/blocks.js +1 -0
  10. package/dist/src/dsl/definitions/brain-types.js +4 -0
  11. package/dist/src/dsl/definitions/events.js +2 -0
  12. package/dist/src/dsl/definitions/run-params.js +1 -0
  13. package/dist/src/dsl/definitions/steps.js +2 -0
  14. package/dist/src/dsl/execution/constants.js +14 -0
  15. package/dist/src/dsl/execution/event-stream.js +1638 -0
  16. package/dist/src/dsl/execution/retry.js +298 -0
  17. package/dist/src/dsl/types.js +2 -2
  18. package/dist/src/index.js +5 -3
  19. package/dist/src/tools/index.js +181 -0
  20. package/dist/src/ui/component-utils.js +107 -0
  21. package/dist/src/ui/generate-page-html.js +36 -0
  22. package/dist/src/ui/generate-ui.js +601 -0
  23. package/dist/src/ui/types.js +165 -0
  24. package/dist/src/ui/validate-form.js +428 -0
  25. package/dist/src/yaml/data-validator.js +302 -0
  26. package/dist/src/yaml/index.js +9 -0
  27. package/dist/src/yaml/parser.js +224 -0
  28. package/dist/src/yaml/schema-extractor.js +330 -0
  29. package/dist/src/yaml/type-inference.js +210 -0
  30. package/dist/src/yaml/types.js +12 -0
  31. package/dist/types/clients/types.d.ts +42 -0
  32. package/dist/types/clients/types.d.ts.map +1 -1
  33. package/dist/types/dsl/agent-messages.d.ts +18 -0
  34. package/dist/types/dsl/agent-messages.d.ts.map +1 -0
  35. package/dist/types/dsl/brain-runner.d.ts +2 -2
  36. package/dist/types/dsl/brain-runner.d.ts.map +1 -1
  37. package/dist/types/dsl/brain-state-machine.d.ts.map +1 -1
  38. package/dist/types/dsl/brain.d.ts +7 -273
  39. package/dist/types/dsl/brain.d.ts.map +1 -1
  40. package/dist/types/dsl/builder/brain.d.ts +200 -0
  41. package/dist/types/dsl/builder/brain.d.ts.map +1 -0
  42. package/dist/types/dsl/builder/step.d.ts +15 -0
  43. package/dist/types/dsl/builder/step.d.ts.map +1 -0
  44. package/dist/types/dsl/constants.d.ts +8 -9
  45. package/dist/types/dsl/constants.d.ts.map +1 -1
  46. package/dist/types/dsl/create-brain.d.ts +80 -0
  47. package/dist/types/dsl/create-brain.d.ts.map +1 -0
  48. package/dist/types/dsl/definitions/blocks.d.ts +62 -0
  49. package/dist/types/dsl/definitions/blocks.d.ts.map +1 -0
  50. package/dist/types/dsl/definitions/brain-types.d.ts +33 -0
  51. package/dist/types/dsl/definitions/brain-types.d.ts.map +1 -0
  52. package/dist/types/dsl/definitions/events.d.ts +129 -0
  53. package/dist/types/dsl/definitions/events.d.ts.map +1 -0
  54. package/dist/types/dsl/definitions/run-params.d.ts +26 -0
  55. package/dist/types/dsl/definitions/run-params.d.ts.map +1 -0
  56. package/dist/types/dsl/definitions/steps.d.ts +20 -0
  57. package/dist/types/dsl/definitions/steps.d.ts.map +1 -0
  58. package/dist/types/dsl/example-webhook.d.ts +1 -1
  59. package/dist/types/dsl/example-webhook.d.ts.map +1 -1
  60. package/dist/types/dsl/execution/constants.d.ts +16 -0
  61. package/dist/types/dsl/execution/constants.d.ts.map +1 -0
  62. package/dist/types/dsl/execution/event-stream.d.ts +44 -0
  63. package/dist/types/dsl/execution/event-stream.d.ts.map +1 -0
  64. package/dist/types/dsl/execution/retry.d.ts +30 -0
  65. package/dist/types/dsl/execution/retry.d.ts.map +1 -0
  66. package/dist/types/dsl/types.d.ts +35 -14
  67. package/dist/types/dsl/types.d.ts.map +1 -1
  68. package/dist/types/index.d.ts +9 -7
  69. package/dist/types/index.d.ts.map +1 -1
  70. package/dist/types/tools/index.d.ts +33 -0
  71. package/dist/types/tools/index.d.ts.map +1 -0
  72. package/dist/types/ui/component-utils.d.ts +19 -0
  73. package/dist/types/ui/component-utils.d.ts.map +1 -0
  74. package/dist/types/ui/generate-page-html.d.ts +39 -0
  75. package/dist/types/ui/generate-page-html.d.ts.map +1 -0
  76. package/dist/types/ui/generate-ui.d.ts +47 -0
  77. package/dist/types/ui/generate-ui.d.ts.map +1 -0
  78. package/dist/types/ui/types.d.ts +138 -0
  79. package/dist/types/ui/types.d.ts.map +1 -0
  80. package/dist/types/ui/validate-form.d.ts +45 -0
  81. package/dist/types/ui/validate-form.d.ts.map +1 -0
  82. package/dist/types/yaml/data-validator.d.ts +35 -0
  83. package/dist/types/yaml/data-validator.d.ts.map +1 -0
  84. package/dist/types/yaml/index.d.ts +11 -0
  85. package/dist/types/yaml/index.d.ts.map +1 -0
  86. package/dist/types/yaml/parser.d.ts +20 -0
  87. package/dist/types/yaml/parser.d.ts.map +1 -0
  88. package/dist/types/yaml/schema-extractor.d.ts +29 -0
  89. package/dist/types/yaml/schema-extractor.d.ts.map +1 -0
  90. package/dist/types/yaml/type-inference.d.ts +50 -0
  91. package/dist/types/yaml/type-inference.d.ts.map +1 -0
  92. package/dist/types/yaml/types.d.ts +89 -0
  93. package/dist/types/yaml/types.d.ts.map +1 -0
  94. package/package.json +4 -2
  95. package/dist/types/dsl/loop-messages.d.ts +0 -18
  96. package/dist/types/dsl/loop-messages.d.ts.map +0 -1
@@ -0,0 +1,75 @@
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
+ import { v4 as uuidv4 } from 'uuid';
34
+ import { STATUS } from '../constants.js';
35
+ export var Step = /*#__PURE__*/ function() {
36
+ "use strict";
37
+ function Step(block, id) {
38
+ _class_call_check(this, Step);
39
+ _define_property(this, "block", void 0);
40
+ _define_property(this, "id", void 0);
41
+ _define_property(this, "patch", void 0);
42
+ _define_property(this, "status", void 0);
43
+ this.block = block;
44
+ this.status = STATUS.PENDING;
45
+ this.id = id || uuidv4();
46
+ }
47
+ _create_class(Step, [
48
+ {
49
+ key: "withPatch",
50
+ value: function withPatch(patch) {
51
+ this.patch = patch;
52
+ return this;
53
+ }
54
+ },
55
+ {
56
+ key: "withStatus",
57
+ value: function withStatus(status) {
58
+ this.status = status;
59
+ return this;
60
+ }
61
+ },
62
+ {
63
+ key: "serialized",
64
+ get: function get() {
65
+ return {
66
+ id: this.id,
67
+ title: this.block.title,
68
+ status: this.status,
69
+ patch: typeof this.patch === 'string' ? JSON.parse(this.patch) : this.patch
70
+ };
71
+ }
72
+ }
73
+ ]);
74
+ return Step;
75
+ }();
@@ -10,16 +10,15 @@ export var BRAIN_EVENTS = {
10
10
  CANCELLED: 'brain:cancelled',
11
11
  WEBHOOK: 'brain:webhook',
12
12
  WEBHOOK_RESPONSE: 'brain:webhook_response',
13
- HEARTBEAT: 'brain:heartbeat',
14
- // Loop step events
15
- LOOP_START: 'loop:start',
16
- LOOP_ITERATION: 'loop:iteration',
17
- LOOP_TOOL_CALL: 'loop:tool_call',
18
- LOOP_TOOL_RESULT: 'loop:tool_result',
19
- LOOP_ASSISTANT_MESSAGE: 'loop:assistant_message',
20
- LOOP_COMPLETE: 'loop:complete',
21
- LOOP_TOKEN_LIMIT: 'loop:token_limit',
22
- LOOP_WEBHOOK: 'loop:webhook'
13
+ // Agent step events
14
+ AGENT_START: 'agent:start',
15
+ AGENT_ITERATION: 'agent:iteration',
16
+ AGENT_TOOL_CALL: 'agent:tool_call',
17
+ AGENT_TOOL_RESULT: 'agent:tool_result',
18
+ AGENT_ASSISTANT_MESSAGE: 'agent:assistant_message',
19
+ AGENT_COMPLETE: 'agent:complete',
20
+ AGENT_TOKEN_LIMIT: 'agent:token_limit',
21
+ AGENT_WEBHOOK: 'agent:webhook'
23
22
  };
24
23
  export var STATUS = {
25
24
  PENDING: 'pending',
@@ -0,0 +1,63 @@
1
+ import { brain as coreBrain } from './builder/brain.js';
2
+ /**
3
+ * Creates a project-level brain function with pre-configured services, components, and tools.
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
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // brain.ts - your project's brain configuration
13
+ * import { createBrain } from '@positronic/core';
14
+ * import { components } from './components/index.js';
15
+ * import slack from './services/slack.js';
16
+ * import gmail from './services/gmail.js';
17
+ *
18
+ * export const brain = createBrain({
19
+ * services: { slack, gmail },
20
+ * components,
21
+ * });
22
+ * ```
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
+ */ export function createBrain(config) {
44
+ var services = config.services, components = config.components, defaultTools = config.defaultTools;
45
+ // Implementation
46
+ function brain(titleOrConfig, agentConfig) {
47
+ var base = coreBrain(titleOrConfig);
48
+ if (components) {
49
+ base = base.withComponents(components);
50
+ }
51
+ if (defaultTools) {
52
+ base = base.withTools(defaultTools);
53
+ }
54
+ if (services) {
55
+ base = base.withServices(services);
56
+ }
57
+ if (agentConfig) {
58
+ return base.brain('main', agentConfig);
59
+ }
60
+ return base;
61
+ }
62
+ return brain;
63
+ }
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Configuration for creating a brain - either a simple string title
3
+ * or an object with title and optional description.
4
+ */ export { };
@@ -0,0 +1,2 @@
1
+ // Union type of all possible events
2
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,2 @@
1
+ // Type for brain structure
2
+ export { };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Default runtime environment used when env is not provided.
3
+ * This ensures backward compatibility with existing code.
4
+ */ export var DEFAULT_ENV = {
5
+ origin: 'http://localhost:3000',
6
+ secrets: {}
7
+ };
8
+ /**
9
+ * Default system prompt prepended to all agent steps.
10
+ * Explains tool execution quirks to the LLM.
11
+ */ export var DEFAULT_AGENT_SYSTEM_PROMPT = "## Tool Execution Behavior\n- Tools are executed sequentially in the order you call them\n- If a tool triggers a webhook (e.g., human approval), remaining tools in your response will NOT execute - you'll need to call them again after resuming\n- When waiting on multiple webhooks (e.g., Slack + email), the first webhook response received will resume execution\n- Terminal tools end the agent immediately - no further tools or iterations will run\n\n## Resumption Context\nWhen resuming after a webhook response, that response appears as the tool result in your conversation history.";
12
+ /**
13
+ * Maximum number of retries for step execution.
14
+ */ export var MAX_RETRIES = 1;