@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.
- package/dist/src/dsl/{loop-messages.js → agent-messages.js} +21 -21
- package/dist/src/dsl/brain-runner.js +6 -6
- package/dist/src/dsl/brain-state-machine.js +2 -2
- package/dist/src/dsl/brain.js +5 -1912
- package/dist/src/dsl/builder/brain.js +944 -0
- package/dist/src/dsl/builder/step.js +75 -0
- package/dist/src/dsl/constants.js +9 -10
- package/dist/src/dsl/create-brain.js +63 -0
- package/dist/src/dsl/definitions/blocks.js +1 -0
- package/dist/src/dsl/definitions/brain-types.js +4 -0
- package/dist/src/dsl/definitions/events.js +2 -0
- package/dist/src/dsl/definitions/run-params.js +1 -0
- package/dist/src/dsl/definitions/steps.js +2 -0
- package/dist/src/dsl/execution/constants.js +14 -0
- package/dist/src/dsl/execution/event-stream.js +1638 -0
- package/dist/src/dsl/execution/retry.js +298 -0
- package/dist/src/dsl/types.js +2 -2
- package/dist/src/index.js +5 -3
- package/dist/src/tools/index.js +181 -0
- package/dist/src/ui/component-utils.js +107 -0
- package/dist/src/ui/generate-page-html.js +36 -0
- package/dist/src/ui/generate-ui.js +601 -0
- package/dist/src/ui/types.js +165 -0
- package/dist/src/ui/validate-form.js +428 -0
- package/dist/src/yaml/data-validator.js +302 -0
- package/dist/src/yaml/index.js +9 -0
- package/dist/src/yaml/parser.js +224 -0
- package/dist/src/yaml/schema-extractor.js +330 -0
- package/dist/src/yaml/type-inference.js +210 -0
- package/dist/src/yaml/types.js +12 -0
- package/dist/types/clients/types.d.ts +42 -0
- package/dist/types/clients/types.d.ts.map +1 -1
- package/dist/types/dsl/agent-messages.d.ts +18 -0
- package/dist/types/dsl/agent-messages.d.ts.map +1 -0
- package/dist/types/dsl/brain-runner.d.ts +2 -2
- package/dist/types/dsl/brain-runner.d.ts.map +1 -1
- package/dist/types/dsl/brain-state-machine.d.ts.map +1 -1
- package/dist/types/dsl/brain.d.ts +7 -273
- package/dist/types/dsl/brain.d.ts.map +1 -1
- package/dist/types/dsl/builder/brain.d.ts +200 -0
- package/dist/types/dsl/builder/brain.d.ts.map +1 -0
- package/dist/types/dsl/builder/step.d.ts +15 -0
- package/dist/types/dsl/builder/step.d.ts.map +1 -0
- package/dist/types/dsl/constants.d.ts +8 -9
- package/dist/types/dsl/constants.d.ts.map +1 -1
- package/dist/types/dsl/create-brain.d.ts +80 -0
- package/dist/types/dsl/create-brain.d.ts.map +1 -0
- package/dist/types/dsl/definitions/blocks.d.ts +62 -0
- package/dist/types/dsl/definitions/blocks.d.ts.map +1 -0
- package/dist/types/dsl/definitions/brain-types.d.ts +33 -0
- package/dist/types/dsl/definitions/brain-types.d.ts.map +1 -0
- package/dist/types/dsl/definitions/events.d.ts +129 -0
- package/dist/types/dsl/definitions/events.d.ts.map +1 -0
- package/dist/types/dsl/definitions/run-params.d.ts +26 -0
- package/dist/types/dsl/definitions/run-params.d.ts.map +1 -0
- package/dist/types/dsl/definitions/steps.d.ts +20 -0
- package/dist/types/dsl/definitions/steps.d.ts.map +1 -0
- package/dist/types/dsl/example-webhook.d.ts +1 -1
- package/dist/types/dsl/example-webhook.d.ts.map +1 -1
- package/dist/types/dsl/execution/constants.d.ts +16 -0
- package/dist/types/dsl/execution/constants.d.ts.map +1 -0
- package/dist/types/dsl/execution/event-stream.d.ts +44 -0
- package/dist/types/dsl/execution/event-stream.d.ts.map +1 -0
- package/dist/types/dsl/execution/retry.d.ts +30 -0
- package/dist/types/dsl/execution/retry.d.ts.map +1 -0
- package/dist/types/dsl/types.d.ts +35 -14
- package/dist/types/dsl/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +9 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/tools/index.d.ts +33 -0
- package/dist/types/tools/index.d.ts.map +1 -0
- package/dist/types/ui/component-utils.d.ts +19 -0
- package/dist/types/ui/component-utils.d.ts.map +1 -0
- package/dist/types/ui/generate-page-html.d.ts +39 -0
- package/dist/types/ui/generate-page-html.d.ts.map +1 -0
- package/dist/types/ui/generate-ui.d.ts +47 -0
- package/dist/types/ui/generate-ui.d.ts.map +1 -0
- package/dist/types/ui/types.d.ts +138 -0
- package/dist/types/ui/types.d.ts.map +1 -0
- package/dist/types/ui/validate-form.d.ts +45 -0
- package/dist/types/ui/validate-form.d.ts.map +1 -0
- package/dist/types/yaml/data-validator.d.ts +35 -0
- package/dist/types/yaml/data-validator.d.ts.map +1 -0
- package/dist/types/yaml/index.d.ts +11 -0
- package/dist/types/yaml/index.d.ts.map +1 -0
- package/dist/types/yaml/parser.d.ts +20 -0
- package/dist/types/yaml/parser.d.ts.map +1 -0
- package/dist/types/yaml/schema-extractor.d.ts +29 -0
- package/dist/types/yaml/schema-extractor.d.ts.map +1 -0
- package/dist/types/yaml/type-inference.d.ts +50 -0
- package/dist/types/yaml/type-inference.d.ts.map +1 -0
- package/dist/types/yaml/types.d.ts +89 -0
- package/dist/types/yaml/types.d.ts.map +1 -0
- package/package.json +4 -2
- package/dist/types/dsl/loop-messages.d.ts +0 -18
- 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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 @@
|
|
|
1
|
+
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;
|