@noetic-tools/types 0.1.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 +19 -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 +54 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +29 -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 +68 -0
- package/dist/types/common.js +1 -0
- package/dist/types/context-parts/item-log.d.ts +6 -0
- package/dist/types/context-parts/item-log.js +1 -0
- package/dist/types/context-parts/layer-usage.d.ts +18 -0
- package/dist/types/context-parts/layer-usage.js +1 -0
- package/dist/types/context.d.ts +202 -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/error.d.ts +66 -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 +131 -0
- package/dist/types/items.js +2 -0
- package/dist/types/memory-context.d.ts +39 -0
- package/dist/types/memory-context.js +1 -0
- package/dist/types/memory.d.ts +305 -0
- package/dist/types/memory.js +13 -0
- package/dist/types/observability.d.ts +30 -0
- package/dist/types/observability.js +1 -0
- package/dist/types/runtime.d.ts +256 -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 +231 -0
- package/dist/types/step.js +1 -0
- package/dist/types/subprocess-adapter.d.ts +157 -0
- package/dist/types/subprocess-adapter.js +3 -0
- package/dist/types/tool-context.d.ts +34 -0
- package/dist/types/tool-context.js +1 -0
- package/dist/types/tool.d.ts +64 -0
- package/dist/types/tool.js +1 -0
- package/dist/util/framework-cast.d.ts +10 -0
- package/dist/util/framework-cast.js +16 -0
- package/dist/util/message-helpers.d.ts +17 -0
- package/dist/util/message-helpers.js +64 -0
- package/package.json +73 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Explicit cast for framework boundaries where TypeScript's type system
|
|
3
|
+
* cannot express the relationship between input and output types.
|
|
4
|
+
*
|
|
5
|
+
* Used for: pass-through returns (branch null route, loop feedback),
|
|
6
|
+
* raw LLM text output, type-erased collections, and cross-library bridges.
|
|
7
|
+
*
|
|
8
|
+
* This is the single approved location for unsafe type coercion in the codebase.
|
|
9
|
+
*/
|
|
10
|
+
// Declared return type differs from the parameter type intentionally —
|
|
11
|
+
// callers specify T to bridge a framework type gap that TypeScript cannot express.
|
|
12
|
+
// The runtime value is returned unchanged (identity function).
|
|
13
|
+
export function frameworkCast(value) {
|
|
14
|
+
// @ts-expect-error — intentional unsafe coercion at framework boundary
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LLMResponse } from '../types/common.js';
|
|
2
|
+
import type { Context } from '../types/context.js';
|
|
3
|
+
import type { InputMessageItem, Item, MessageItem } from '../types/items.js';
|
|
4
|
+
export declare function isAssistantMessage(item: unknown): item is MessageItem;
|
|
5
|
+
export declare function isUserMessage(item: unknown): item is MessageItem;
|
|
6
|
+
export declare function isOutputText(part: {
|
|
7
|
+
type: string;
|
|
8
|
+
}): part is {
|
|
9
|
+
type: 'output_text';
|
|
10
|
+
text: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function createMessage(text: string, role: 'user' | 'developer'): InputMessageItem;
|
|
13
|
+
export declare function extractAssistantText(items: ReadonlyArray<Item>): string;
|
|
14
|
+
/** Naive token estimate: ~4 chars per token */
|
|
15
|
+
export declare function estimateTokens(text: string): number;
|
|
16
|
+
/** Accumulate token usage and cost from an LLM response onto a mutable context. */
|
|
17
|
+
export declare function trackUsage(ctx: Context, response: LLMResponse): void;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function canTrackUsage(ctx) {
|
|
2
|
+
const desc = Object.getOwnPropertyDescriptor(ctx, 'stepCount');
|
|
3
|
+
return desc !== undefined && desc.writable !== false;
|
|
4
|
+
}
|
|
5
|
+
export function isAssistantMessage(item) {
|
|
6
|
+
return (typeof item === 'object' &&
|
|
7
|
+
item !== null &&
|
|
8
|
+
'type' in item &&
|
|
9
|
+
item.type === 'message' &&
|
|
10
|
+
'role' in item &&
|
|
11
|
+
item.role === 'assistant');
|
|
12
|
+
}
|
|
13
|
+
export function isUserMessage(item) {
|
|
14
|
+
return (typeof item === 'object' &&
|
|
15
|
+
item !== null &&
|
|
16
|
+
'type' in item &&
|
|
17
|
+
item.type === 'message' &&
|
|
18
|
+
'role' in item &&
|
|
19
|
+
item.role === 'user');
|
|
20
|
+
}
|
|
21
|
+
export function isOutputText(part) {
|
|
22
|
+
return part.type === 'output_text';
|
|
23
|
+
}
|
|
24
|
+
export function createMessage(text, role) {
|
|
25
|
+
return {
|
|
26
|
+
id: crypto.randomUUID(),
|
|
27
|
+
status: 'completed',
|
|
28
|
+
type: 'message',
|
|
29
|
+
role,
|
|
30
|
+
content: [
|
|
31
|
+
{
|
|
32
|
+
type: 'input_text',
|
|
33
|
+
text,
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function extractAssistantText(items) {
|
|
39
|
+
const lastMsg = items.findLast(isAssistantMessage);
|
|
40
|
+
if (!lastMsg) {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
return (lastMsg.content
|
|
44
|
+
?.filter(isOutputText)
|
|
45
|
+
?.map((c) => c.text)
|
|
46
|
+
?.join('') ?? '');
|
|
47
|
+
}
|
|
48
|
+
/** Naive token estimate: ~4 chars per token */
|
|
49
|
+
export function estimateTokens(text) {
|
|
50
|
+
return Math.ceil(text.length / 4);
|
|
51
|
+
}
|
|
52
|
+
/** Accumulate token usage and cost from an LLM response onto a mutable context. */
|
|
53
|
+
export function trackUsage(ctx, response) {
|
|
54
|
+
if (!canTrackUsage(ctx)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
ctx.tokens.input += response.usage.inputTokens;
|
|
58
|
+
ctx.tokens.output += response.usage.outputTokens;
|
|
59
|
+
ctx.tokens.total += response.usage.inputTokens + response.usage.outputTokens;
|
|
60
|
+
ctx.tokens.cached = (ctx.tokens.cached ?? 0) + (response.usage.cachedTokens ?? 0);
|
|
61
|
+
if (response.cost) {
|
|
62
|
+
ctx.cost = ctx.cost + response.cost;
|
|
63
|
+
}
|
|
64
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@noetic-tools/types",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Foundational type contracts and primitives shared across the Noetic framework (items, LLM config, adapters, steering, errors).",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/mattapperson/noetic.git",
|
|
10
|
+
"directory": "packages/types"
|
|
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
|
+
"types",
|
|
20
|
+
"contracts"
|
|
21
|
+
],
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./contract": {
|
|
30
|
+
"types": "./dist/types/memory.d.ts",
|
|
31
|
+
"default": "./dist/types/memory.js"
|
|
32
|
+
},
|
|
33
|
+
"./package.json": "./package.json"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@openrouter/agent": "^0.6.0",
|
|
45
|
+
"bun-types": "latest"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@openrouter/agent": "^0.6.0",
|
|
49
|
+
"zod": "^4.0.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"@openrouter/agent": {
|
|
53
|
+
"optional": true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@openrouter/agent": "^0.6.0",
|
|
58
|
+
"zod": "^4.0.0"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "bunx tsc -p tsconfig.build.json && bun scripts/add-js-extensions.ts",
|
|
62
|
+
"verify:esm": "bun scripts/verify-node-esm.ts",
|
|
63
|
+
"prepublishOnly": "rm -rf dist && bun run build && bun run verify:esm",
|
|
64
|
+
"test": "bun test",
|
|
65
|
+
"test:coverage": "bun test --coverage --coverage-reporter=text --coverage-reporter=lcov",
|
|
66
|
+
"test:ci": "bun test --coverage --coverage-reporter=lcov",
|
|
67
|
+
"typecheck": "bunx tsc --noEmit",
|
|
68
|
+
"lint": "bunx biome check .",
|
|
69
|
+
"lint:fix": "bunx biome check --fix .",
|
|
70
|
+
"format": "bunx biome format --write .",
|
|
71
|
+
"format:check": "bunx biome format ."
|
|
72
|
+
}
|
|
73
|
+
}
|