@townco/agent 0.1.83 → 0.1.85
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/acp-server/adapter.js +140 -43
- package/dist/acp-server/http.js +55 -0
- package/dist/acp-server/session-storage.d.ts +31 -6
- package/dist/acp-server/session-storage.js +60 -1
- package/dist/definition/index.d.ts +2 -4
- package/dist/definition/index.js +1 -2
- package/dist/runner/agent-runner.d.ts +2 -3
- package/dist/runner/hooks/executor.d.ts +5 -2
- package/dist/runner/hooks/executor.js +26 -2
- package/dist/runner/hooks/predefined/document-context-extractor/chunk-manager.d.ts +37 -0
- package/dist/runner/hooks/predefined/document-context-extractor/chunk-manager.js +134 -0
- package/dist/runner/hooks/predefined/document-context-extractor/content-extractor.d.ts +20 -0
- package/dist/runner/hooks/predefined/document-context-extractor/content-extractor.js +171 -0
- package/dist/runner/hooks/predefined/document-context-extractor/extraction-state.d.ts +57 -0
- package/dist/runner/hooks/predefined/document-context-extractor/extraction-state.js +126 -0
- package/dist/runner/hooks/predefined/document-context-extractor/index.d.ts +22 -0
- package/dist/runner/hooks/predefined/document-context-extractor/index.js +338 -0
- package/dist/runner/hooks/predefined/document-context-extractor/relevance-scorer.d.ts +19 -0
- package/dist/runner/hooks/predefined/document-context-extractor/relevance-scorer.js +156 -0
- package/dist/runner/hooks/predefined/document-context-extractor/types.d.ts +130 -0
- package/dist/runner/hooks/predefined/document-context-extractor/types.js +8 -0
- package/dist/runner/hooks/predefined/tool-response-compactor.d.ts +0 -4
- package/dist/runner/hooks/predefined/tool-response-compactor.js +101 -222
- package/dist/runner/hooks/types.d.ts +18 -12
- package/dist/runner/langchain/index.js +64 -11
- package/dist/runner/langchain/tools/artifacts.js +6 -9
- package/dist/runner/langchain/tools/document_extract.d.ts +26 -0
- package/dist/runner/langchain/tools/document_extract.js +135 -0
- package/dist/runner/tools.d.ts +2 -2
- package/dist/runner/tools.js +1 -0
- package/dist/templates/index.d.ts +1 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/context-size-calculator.d.ts +1 -10
- package/dist/utils/context-size-calculator.js +1 -12
- package/package.json +6 -6
- package/templates/index.ts +1 -2
|
@@ -12,25 +12,16 @@ export interface ContextSize {
|
|
|
12
12
|
toolInputTokens: number;
|
|
13
13
|
toolResultsTokens: number;
|
|
14
14
|
totalEstimated: number;
|
|
15
|
-
llmReportedInputTokens?: number | undefined;
|
|
16
15
|
modelContextWindow?: number;
|
|
17
16
|
}
|
|
18
17
|
/**
|
|
19
18
|
* Calculate the full context size by counting ALL tokens in the provided messages.
|
|
20
19
|
* This should be called every time a new context entry is created.
|
|
21
20
|
*
|
|
22
|
-
* How LLM-reported tokens work:
|
|
23
|
-
* - The LLM API returns `usage_metadata.input_tokens` which is the ACTUAL token
|
|
24
|
-
* count for EVERYTHING sent to the API: system prompt, tool declarations,
|
|
25
|
-
* all messages, and all tool results
|
|
26
|
-
* - We pass this as `llmReportedTokens` for comparison with our estimate
|
|
27
|
-
* - This helps us validate the accuracy of our tokenizer estimates
|
|
28
|
-
*
|
|
29
21
|
* @param messages - Resolved messages from context entry
|
|
30
22
|
* @param systemPrompt - Base system prompt (without TODO instructions)
|
|
31
|
-
* @param llmReportedTokens - From API usage_metadata.input_tokens
|
|
32
23
|
* @param toolOverheadTokens - Pre-calculated tool overhead (built-in/custom/filesystem tool definitions + TODO instructions)
|
|
33
24
|
* @param mcpOverheadTokens - Pre-calculated MCP tool overhead (MCP tool definitions)
|
|
34
25
|
* @param modelContextWindow - Model's max context window size
|
|
35
26
|
*/
|
|
36
|
-
export declare function calculateContextSize(messages: SessionMessage[], systemPrompt?: string,
|
|
27
|
+
export declare function calculateContextSize(messages: SessionMessage[], systemPrompt?: string, toolOverheadTokens?: number, mcpOverheadTokens?: number, modelContextWindow?: number): ContextSize;
|
|
@@ -31,21 +31,13 @@ function countContentBlock(block) {
|
|
|
31
31
|
* Calculate the full context size by counting ALL tokens in the provided messages.
|
|
32
32
|
* This should be called every time a new context entry is created.
|
|
33
33
|
*
|
|
34
|
-
* How LLM-reported tokens work:
|
|
35
|
-
* - The LLM API returns `usage_metadata.input_tokens` which is the ACTUAL token
|
|
36
|
-
* count for EVERYTHING sent to the API: system prompt, tool declarations,
|
|
37
|
-
* all messages, and all tool results
|
|
38
|
-
* - We pass this as `llmReportedTokens` for comparison with our estimate
|
|
39
|
-
* - This helps us validate the accuracy of our tokenizer estimates
|
|
40
|
-
*
|
|
41
34
|
* @param messages - Resolved messages from context entry
|
|
42
35
|
* @param systemPrompt - Base system prompt (without TODO instructions)
|
|
43
|
-
* @param llmReportedTokens - From API usage_metadata.input_tokens
|
|
44
36
|
* @param toolOverheadTokens - Pre-calculated tool overhead (built-in/custom/filesystem tool definitions + TODO instructions)
|
|
45
37
|
* @param mcpOverheadTokens - Pre-calculated MCP tool overhead (MCP tool definitions)
|
|
46
38
|
* @param modelContextWindow - Model's max context window size
|
|
47
39
|
*/
|
|
48
|
-
export function calculateContextSize(messages, systemPrompt,
|
|
40
|
+
export function calculateContextSize(messages, systemPrompt, toolOverheadTokens, mcpOverheadTokens, modelContextWindow) {
|
|
49
41
|
const systemPromptTokens = systemPrompt ? countTokens(systemPrompt) : 0;
|
|
50
42
|
const toolOverheadTokensEstimate = toolOverheadTokens ?? 0;
|
|
51
43
|
const mcpOverheadTokensEstimate = mcpOverheadTokens ?? 0;
|
|
@@ -89,9 +81,6 @@ export function calculateContextSize(messages, systemPrompt, llmReportedTokens,
|
|
|
89
81
|
if (mcpOverheadTokensEstimate > 0) {
|
|
90
82
|
result.mcpOverheadTokens = mcpOverheadTokensEstimate;
|
|
91
83
|
}
|
|
92
|
-
if (llmReportedTokens !== undefined) {
|
|
93
|
-
result.llmReportedInputTokens = llmReportedTokens;
|
|
94
|
-
}
|
|
95
84
|
if (modelContextWindow !== undefined) {
|
|
96
85
|
result.modelContextWindow = modelContextWindow;
|
|
97
86
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@townco/agent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.85",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"module": "index.ts",
|
|
6
6
|
"files": [
|
|
@@ -78,12 +78,12 @@
|
|
|
78
78
|
"@opentelemetry/sdk-trace-base": "^1.28.0",
|
|
79
79
|
"@opentelemetry/sdk-trace-node": "^1.28.0",
|
|
80
80
|
"@opentelemetry/semantic-conventions": "^1.28.0",
|
|
81
|
-
"@townco/core": "0.0.
|
|
82
|
-
"@townco/gui-template": "0.1.
|
|
81
|
+
"@townco/core": "0.0.58",
|
|
82
|
+
"@townco/gui-template": "0.1.77",
|
|
83
83
|
"@townco/supabase": "workspace:*",
|
|
84
|
-
"@townco/tsconfig": "0.1.
|
|
85
|
-
"@townco/tui-template": "0.1.
|
|
86
|
-
"@townco/ui": "0.1.
|
|
84
|
+
"@townco/tsconfig": "0.1.77",
|
|
85
|
+
"@townco/tui-template": "0.1.77",
|
|
86
|
+
"@townco/ui": "0.1.80",
|
|
87
87
|
"exa-js": "^2.0.0",
|
|
88
88
|
"hono": "^4.10.4",
|
|
89
89
|
"langchain": "^1.0.3",
|
package/templates/index.ts
CHANGED