@noetic-tools/core 0.0.1
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/LICENSE +201 -0
- package/README.md +38 -0
- package/dist/adapters/in-memory-fs-adapter.d.ts +3 -0
- package/dist/adapters/in-memory-fs-adapter.js +245 -0
- package/dist/adapters/in-memory-shell-adapter.d.ts +9 -0
- package/dist/adapters/in-memory-shell-adapter.js +20 -0
- package/dist/adapters/in-memory-subprocess-adapter.d.ts +5 -0
- package/dist/adapters/in-memory-subprocess-adapter.js +126 -0
- package/dist/adapters/local-fs-adapter.d.ts +3 -0
- package/dist/adapters/local-fs-adapter.js +43 -0
- package/dist/adapters/local-shell-adapter.d.ts +51 -0
- package/dist/adapters/local-shell-adapter.js +167 -0
- package/dist/adapters/local-subprocess-adapter.d.ts +16 -0
- package/dist/adapters/local-subprocess-adapter.js +187 -0
- package/dist/adapters/openrouter.d.ts +57 -0
- package/dist/adapters/openrouter.js +248 -0
- package/dist/builders/channel-builder.d.ts +36 -0
- package/dist/builders/channel-builder.js +15 -0
- package/dist/builders/control-flow-builders.d.ts +79 -0
- package/dist/builders/control-flow-builders.js +53 -0
- package/dist/builders/every.d.ts +45 -0
- package/dist/builders/every.js +60 -0
- package/dist/builders/layer-provides-builders.d.ts +32 -0
- package/dist/builders/layer-provides-builders.js +33 -0
- package/dist/builders/loop-builder.d.ts +23 -0
- package/dist/builders/loop-builder.js +46 -0
- package/dist/builders/memory-builder.d.ts +11 -0
- package/dist/builders/memory-builder.js +15 -0
- package/dist/builders/provide-builder.d.ts +20 -0
- package/dist/builders/provide-builder.js +34 -0
- package/dist/builders/spawn-builder.d.ts +20 -0
- package/dist/builders/spawn-builder.js +33 -0
- package/dist/builders/step-builders.d.ts +62 -0
- package/dist/builders/step-builders.js +99 -0
- package/dist/builders/tool-builder.d.ts +52 -0
- package/dist/builders/tool-builder.js +59 -0
- package/dist/conditions/conditions.d.ts +114 -0
- package/dist/conditions/conditions.js +271 -0
- package/dist/conditions/cosine-similarity.d.ts +11 -0
- package/dist/conditions/cosine-similarity.js +28 -0
- package/dist/conditions/index.d.ts +3 -0
- package/dist/conditions/index.js +2 -0
- package/dist/errors/noetic-config-error.d.ts +41 -0
- package/dist/errors/noetic-config-error.js +44 -0
- package/dist/errors/noetic-error.d.ts +18 -0
- package/dist/errors/noetic-error.js +52 -0
- package/dist/index.d.ts +152 -0
- package/dist/index.js +112 -0
- package/dist/internal-test.d.ts +11 -0
- package/dist/internal-test.js +11 -0
- package/dist/interpreter/clone-guard.d.ts +4 -0
- package/dist/interpreter/clone-guard.js +18 -0
- package/dist/interpreter/collect-tools.d.ts +12 -0
- package/dist/interpreter/collect-tools.js +70 -0
- package/dist/interpreter/execute-branch.d.ts +3 -0
- package/dist/interpreter/execute-branch.js +10 -0
- package/dist/interpreter/execute-every.d.ts +15 -0
- package/dist/interpreter/execute-every.js +143 -0
- package/dist/interpreter/execute-fork.d.ts +3 -0
- package/dist/interpreter/execute-fork.js +215 -0
- package/dist/interpreter/execute-llm.d.ts +4 -0
- package/dist/interpreter/execute-llm.js +217 -0
- package/dist/interpreter/execute-loop.d.ts +3 -0
- package/dist/interpreter/execute-loop.js +171 -0
- package/dist/interpreter/execute-provide.d.ts +10 -0
- package/dist/interpreter/execute-provide.js +64 -0
- package/dist/interpreter/execute-run.d.ts +3 -0
- package/dist/interpreter/execute-run.js +39 -0
- package/dist/interpreter/execute-spawn.d.ts +11 -0
- package/dist/interpreter/execute-spawn.js +113 -0
- package/dist/interpreter/execute-tool.d.ts +5 -0
- package/dist/interpreter/execute-tool.js +81 -0
- package/dist/interpreter/execute.d.ts +14 -0
- package/dist/interpreter/execute.js +119 -0
- package/dist/interpreter/framework-cast.d.ts +10 -0
- package/dist/interpreter/framework-cast.js +16 -0
- package/dist/interpreter/message-helpers.d.ts +9 -0
- package/dist/interpreter/message-helpers.js +42 -0
- package/dist/interpreter/typeguards.d.ts +25 -0
- package/dist/interpreter/typeguards.js +50 -0
- package/dist/memory/budget.d.ts +23 -0
- package/dist/memory/budget.js +117 -0
- package/dist/memory/function-call-utils.d.ts +6 -0
- package/dist/memory/function-call-utils.js +25 -0
- package/dist/memory/layer-api.d.ts +14 -0
- package/dist/memory/layer-api.js +91 -0
- package/dist/memory/layer-lifecycle.d.ts +160 -0
- package/dist/memory/layer-lifecycle.js +552 -0
- package/dist/memory/layer-usage.d.ts +15 -0
- package/dist/memory/layer-usage.js +48 -0
- package/dist/memory/layers/durable-task-state.d.ts +79 -0
- package/dist/memory/layers/durable-task-state.js +118 -0
- package/dist/memory/layers/file-reference.d.ts +55 -0
- package/dist/memory/layers/file-reference.js +538 -0
- package/dist/memory/layers/history-window.d.ts +29 -0
- package/dist/memory/layers/history-window.js +114 -0
- package/dist/memory/layers/observational-memory.d.ts +53 -0
- package/dist/memory/layers/observational-memory.js +110 -0
- package/dist/memory/layers/plan.d.ts +55 -0
- package/dist/memory/layers/plan.js +369 -0
- package/dist/memory/layers/static-content.d.ts +27 -0
- package/dist/memory/layers/static-content.js +35 -0
- package/dist/memory/layers/steering.d.ts +51 -0
- package/dist/memory/layers/steering.js +258 -0
- package/dist/memory/layers/tool-memory-layer.d.ts +16 -0
- package/dist/memory/layers/tool-memory-layer.js +43 -0
- package/dist/memory/layers/working-memory.d.ts +44 -0
- package/dist/memory/layers/working-memory.js +92 -0
- package/dist/memory/projector.d.ts +10 -0
- package/dist/memory/projector.js +19 -0
- package/dist/memory/scope.d.ts +3 -0
- package/dist/memory/scope.js +31 -0
- package/dist/memory/strip-unresolved.d.ts +13 -0
- package/dist/memory/strip-unresolved.js +35 -0
- package/dist/observability/genai-attributes.d.ts +11 -0
- package/dist/observability/genai-attributes.js +12 -0
- package/dist/observability/span-impl.d.ts +20 -0
- package/dist/observability/span-impl.js +33 -0
- package/dist/observability/trace-exporter.d.ts +15 -0
- package/dist/observability/trace-exporter.js +26 -0
- package/dist/patterns/flow.d.ts +52 -0
- package/dist/patterns/flow.js +103 -0
- package/dist/patterns/interview.d.ts +53 -0
- package/dist/patterns/interview.js +113 -0
- package/dist/patterns/plans.d.ts +45 -0
- package/dist/patterns/plans.js +125 -0
- package/dist/patterns/ralph-wiggum.d.ts +20 -0
- package/dist/patterns/ralph-wiggum.js +37 -0
- package/dist/patterns/react.d.ts +18 -0
- package/dist/patterns/react.js +39 -0
- package/dist/portable.d.ts +26 -0
- package/dist/portable.js +34 -0
- package/dist/runtime/agent-harness.d.ts +206 -0
- package/dist/runtime/agent-harness.js +1170 -0
- package/dist/runtime/broadcaster-utils.d.ts +30 -0
- package/dist/runtime/broadcaster-utils.js +53 -0
- package/dist/runtime/channel-store.d.ts +18 -0
- package/dist/runtime/channel-store.js +187 -0
- package/dist/runtime/context-impl.d.ts +80 -0
- package/dist/runtime/context-impl.js +140 -0
- package/dist/runtime/cwd-helpers.d.ts +42 -0
- package/dist/runtime/cwd-helpers.js +68 -0
- package/dist/runtime/detached-handle.d.ts +14 -0
- package/dist/runtime/detached-handle.js +56 -0
- package/dist/runtime/event-broadcaster.d.ts +61 -0
- package/dist/runtime/event-broadcaster.js +187 -0
- package/dist/runtime/exec-context-factory.d.ts +25 -0
- package/dist/runtime/exec-context-factory.js +30 -0
- package/dist/runtime/in-memory-storage.d.ts +9 -0
- package/dist/runtime/in-memory-storage.js +33 -0
- package/dist/runtime/item-log-impl.d.ts +11 -0
- package/dist/runtime/item-log-impl.js +25 -0
- package/dist/runtime/message-queue.d.ts +30 -0
- package/dist/runtime/message-queue.js +46 -0
- package/dist/runtime/session-runner.d.ts +77 -0
- package/dist/runtime/session-runner.js +253 -0
- package/dist/runtime/session-streams.d.ts +11 -0
- package/dist/runtime/session-streams.js +204 -0
- package/dist/runtime/tool-memory.d.ts +6 -0
- package/dist/runtime/tool-memory.js +22 -0
- package/dist/schemas/item.d.ts +35 -0
- package/dist/schemas/item.js +155 -0
- package/dist/types/channel.d.ts +29 -0
- package/dist/types/channel.js +1 -0
- package/dist/types/common.d.ts +111 -0
- package/dist/types/common.js +1 -0
- package/dist/types/context.d.ts +93 -0
- package/dist/types/context.js +1 -0
- package/dist/types/detached.d.ts +17 -0
- package/dist/types/detached.js +7 -0
- package/dist/types/embed.d.ts +5 -0
- package/dist/types/embed.js +1 -0
- package/dist/types/error.d.ts +51 -0
- package/dist/types/error.js +1 -0
- package/dist/types/fs-adapter.d.ts +51 -0
- package/dist/types/fs-adapter.js +3 -0
- package/dist/types/harness-result.d.ts +43 -0
- package/dist/types/harness-result.js +2 -0
- package/dist/types/items.d.ts +115 -0
- package/dist/types/items.js +2 -0
- package/dist/types/memory.d.ts +336 -0
- package/dist/types/memory.js +13 -0
- package/dist/types/mutable-context.d.ts +13 -0
- package/dist/types/mutable-context.js +1 -0
- package/dist/types/observability.d.ts +30 -0
- package/dist/types/observability.js +1 -0
- package/dist/types/runtime.d.ts +255 -0
- package/dist/types/runtime.js +1 -0
- package/dist/types/shell-adapter.d.ts +34 -0
- package/dist/types/shell-adapter.js +10 -0
- package/dist/types/steering.d.ts +89 -0
- package/dist/types/steering.js +14 -0
- package/dist/types/step.d.ts +206 -0
- package/dist/types/step.js +1 -0
- package/dist/types/subprocess-adapter.d.ts +41 -0
- package/dist/types/subprocess-adapter.js +1 -0
- package/dist/types/tool-context.d.ts +34 -0
- package/dist/types/tool-context.js +1 -0
- package/dist/unstable.d.ts +28 -0
- package/dist/unstable.js +24 -0
- package/dist/until/combinators.d.ts +17 -0
- package/dist/until/combinators.js +49 -0
- package/dist/until/never.d.ts +9 -0
- package/dist/until/never.js +12 -0
- package/dist/until/predicates.d.ts +43 -0
- package/dist/until/predicates.js +126 -0
- package/package.json +81 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { cosineSimilarity } from '../conditions/cosine-similarity';
|
|
2
|
+
import { never } from './never';
|
|
3
|
+
const CONVERGE_CACHE_KEY = 'converge:previousVector';
|
|
4
|
+
/**
|
|
5
|
+
* Namespace of built-in loop termination predicates.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export const until = {
|
|
10
|
+
/** Stops the loop after `n` steps. @public */
|
|
11
|
+
maxSteps(n) {
|
|
12
|
+
return (snap) => ({
|
|
13
|
+
stop: snap.stepCount >= n,
|
|
14
|
+
reason: snap.stepCount >= n ? `Reached max steps (${n})` : undefined,
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
/** Stops the loop when accumulated cost reaches `usd`. @public */
|
|
18
|
+
maxCost(usd) {
|
|
19
|
+
return (snap) => ({
|
|
20
|
+
stop: snap.cost >= usd,
|
|
21
|
+
reason: snap.cost >= usd ? `Reached max cost ($${usd})` : undefined,
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
/** Stops the loop when elapsed time reaches `ms` milliseconds. @public */
|
|
25
|
+
maxDuration(ms) {
|
|
26
|
+
return (snap) => ({
|
|
27
|
+
stop: snap.elapsed >= ms,
|
|
28
|
+
reason: snap.elapsed >= ms ? `Reached max duration (${ms}ms)` : undefined,
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
/** Stops the loop when the last model response contains no tool calls. @public */
|
|
32
|
+
noToolCalls() {
|
|
33
|
+
return (snap) => {
|
|
34
|
+
if (snap.stepCount < 1) {
|
|
35
|
+
return {
|
|
36
|
+
stop: false,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const meta = snap.lastStepMeta;
|
|
40
|
+
const hasToolCalls = meta?.toolCalls && meta.toolCalls.length > 0;
|
|
41
|
+
return {
|
|
42
|
+
stop: !hasToolCalls,
|
|
43
|
+
reason: !hasToolCalls ? 'No tool calls in last response' : undefined,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
/** Never stops the loop — pairs with operators like `every` that rely on cancellation. @public */
|
|
48
|
+
never,
|
|
49
|
+
/** Stops the loop when the verify function returns `{ pass: true }`. @public */
|
|
50
|
+
verified(fn) {
|
|
51
|
+
return async (snap) => {
|
|
52
|
+
const result = await fn(snap.lastOutput);
|
|
53
|
+
return {
|
|
54
|
+
stop: result.pass,
|
|
55
|
+
reason: result.pass ? 'Verification passed' : undefined,
|
|
56
|
+
feedback: result.feedback,
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
/** Stops the loop when consecutive outputs are similar (exact equality or embedding cosine similarity). @public */
|
|
61
|
+
converged(opts) {
|
|
62
|
+
const threshold = opts.threshold ?? 1;
|
|
63
|
+
const { embed } = opts;
|
|
64
|
+
if (!embed || threshold >= 1) {
|
|
65
|
+
// Exact string equality (original behavior)
|
|
66
|
+
let previousOutput = null;
|
|
67
|
+
return (snap) => {
|
|
68
|
+
const currentText = snap.lastText;
|
|
69
|
+
if (previousOutput === null) {
|
|
70
|
+
previousOutput = currentText;
|
|
71
|
+
return {
|
|
72
|
+
stop: false,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const similar = currentText === previousOutput;
|
|
76
|
+
previousOutput = currentText;
|
|
77
|
+
return {
|
|
78
|
+
stop: similar,
|
|
79
|
+
reason: similar ? 'Output converged' : undefined,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// Embedding-based similarity — embed is narrowed to EmbedFn here
|
|
84
|
+
let previousVector = null;
|
|
85
|
+
const persistVector = async (vector) => {
|
|
86
|
+
if (opts.cache) {
|
|
87
|
+
await opts.cache.set(CONVERGE_CACHE_KEY, vector);
|
|
88
|
+
}
|
|
89
|
+
previousVector = vector;
|
|
90
|
+
};
|
|
91
|
+
return async (snap) => {
|
|
92
|
+
const currentText = snap.lastText;
|
|
93
|
+
const [currentVector] = await embed([
|
|
94
|
+
currentText,
|
|
95
|
+
]);
|
|
96
|
+
// Try to load previous vector from cache if we don't have one in closure
|
|
97
|
+
if (!previousVector && opts.cache) {
|
|
98
|
+
previousVector = await opts.cache.get(CONVERGE_CACHE_KEY);
|
|
99
|
+
}
|
|
100
|
+
if (!previousVector) {
|
|
101
|
+
await persistVector(currentVector);
|
|
102
|
+
return {
|
|
103
|
+
stop: false,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const similarity = cosineSimilarity(currentVector, previousVector);
|
|
107
|
+
await persistVector(currentVector);
|
|
108
|
+
const converged = similarity >= threshold;
|
|
109
|
+
return {
|
|
110
|
+
stop: converged,
|
|
111
|
+
reason: converged ? `Output converged (similarity: ${similarity.toFixed(3)})` : undefined,
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
/** Stops the loop when the last output text contains the given marker string. @public */
|
|
116
|
+
outputContains(marker) {
|
|
117
|
+
return (snap) => ({
|
|
118
|
+
stop: snap.lastText.includes(marker),
|
|
119
|
+
reason: snap.lastText.includes(marker) ? `Output contains marker: ${marker}` : undefined,
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
/** Wraps an arbitrary `Until` function as a named predicate. @public */
|
|
123
|
+
custom(fn) {
|
|
124
|
+
return fn;
|
|
125
|
+
},
|
|
126
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@noetic-tools/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Step primitives, interpreter, runtime, and memory layer contract for Noetic agents.",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/mattapperson/noetic.git",
|
|
10
|
+
"directory": "packages/core"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/mattapperson/noetic#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/mattapperson/noetic/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"noetic",
|
|
18
|
+
"agents",
|
|
19
|
+
"llm",
|
|
20
|
+
"ai",
|
|
21
|
+
"openrouter",
|
|
22
|
+
"agent-framework"
|
|
23
|
+
],
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./portable": {
|
|
32
|
+
"types": "./dist/portable.d.ts",
|
|
33
|
+
"default": "./dist/portable.js"
|
|
34
|
+
},
|
|
35
|
+
"./unstable": {
|
|
36
|
+
"types": "./dist/unstable.d.ts",
|
|
37
|
+
"default": "./dist/unstable.js"
|
|
38
|
+
},
|
|
39
|
+
"./internal/test": {
|
|
40
|
+
"types": "./dist/internal-test.d.ts",
|
|
41
|
+
"default": "./dist/internal-test.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"README.md",
|
|
47
|
+
"LICENSE"
|
|
48
|
+
],
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@openrouter/agent": "^0.6.0",
|
|
54
|
+
"bun-types": "latest"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"@openrouter/agent": "^0.6.0",
|
|
58
|
+
"zod": "^4.0.0"
|
|
59
|
+
},
|
|
60
|
+
"peerDependenciesMeta": {
|
|
61
|
+
"@openrouter/agent": {
|
|
62
|
+
"optional": true
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"dependencies": {
|
|
66
|
+
"@openrouter/agent": "^0.6.0",
|
|
67
|
+
"zod": "^4.0.0"
|
|
68
|
+
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"build": "bunx tsc -p tsconfig.build.json",
|
|
71
|
+
"prepublishOnly": "rm -rf dist && bun run build",
|
|
72
|
+
"test": "bun test",
|
|
73
|
+
"test:coverage": "bun test --coverage --coverage-reporter=text --coverage-reporter=json",
|
|
74
|
+
"test:ci": "bun test --coverage --coverage-reporter=json",
|
|
75
|
+
"typecheck": "bunx tsc --noEmit",
|
|
76
|
+
"lint": "bunx biome check .",
|
|
77
|
+
"lint:fix": "bunx biome check --fix .",
|
|
78
|
+
"format": "bunx biome format --write .",
|
|
79
|
+
"format:check": "bunx biome format ."
|
|
80
|
+
}
|
|
81
|
+
}
|