tinker-agent 1.11.0 → 2.1.0
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/CHANGELOG.md +44 -1
- package/README.md +33 -24
- package/package.json +2 -1
- package/src/agent/context-meter.ts +12 -85
- package/src/agent/loop.ts +1 -14
- package/src/agent/runtime-session.ts +9 -25
- package/src/agent/session-ledger.ts +12 -5
- package/src/agent/tool-result-content.ts +76 -0
- package/src/agent/types.ts +14 -2
- package/src/cli/config.ts +4 -5
- package/src/cli/model-profiles.ts +38 -97
- package/src/cli/public-config-contract.ts +24 -88
- package/src/cli/runner-dependencies.ts +5 -7
- package/src/cli/tui-memory.ts +1 -3
- package/src/cli/tui-runner.tsx +4 -0
- package/src/context/compiled-context-hash.ts +2 -1
- package/src/context/compiled-context-validator.ts +13 -4
- package/src/context/context-protocol-validator.ts +33 -2
- package/src/context/context-revision-compiler.ts +2 -1
- package/src/context/context-revision.ts +8 -2
- package/src/context/context-swap-renderer.ts +46 -12
- package/src/context/prefix-retirement-planner.ts +13 -9
- package/src/context/protocol-frame.ts +74 -7
- package/src/context/swap-planner.ts +19 -14
- package/src/events/observation-text-log.ts +1 -1
- package/src/events/stdout-event-printer.ts +6 -0
- package/src/image/image-asset-store.ts +32 -3
- package/src/image/image-input-policy.ts +53 -2
- package/src/image/image-probe.ts +8 -2
- package/src/image/provider-image.ts +99 -0
- package/src/memory/contracts.ts +61 -3
- package/src/memory/memory-coordinator.ts +313 -49
- package/src/memory/memory-extractor.ts +48 -48
- package/src/memory/memory-get-tool.ts +86 -0
- package/src/memory/memory-search-tool.ts +122 -33
- package/src/memory/memory-store.ts +227 -20
- package/src/model/fake-model-client.ts +177 -124
- package/src/model/model-client.ts +62 -11
- package/src/model/model-request-preflight.ts +0 -1
- package/src/model/openai-chat-mapping.ts +2 -1
- package/src/model/openai-chat-model-client.ts +26 -38
- package/src/model/openai-model-utils.ts +109 -40
- package/src/model/openai-responses-mapping.ts +25 -1
- package/src/model/openai-responses-model-client.ts +27 -40
- package/src/model/token-estimator.ts +26 -3
- package/src/observation/observation-builder.ts +100 -25
- package/src/session/session-history-reader.ts +128 -5
- package/src/session/session-schema.ts +59 -9
- package/src/session/session-store.ts +342 -205
- package/src/tools/registry.ts +18 -0
- package/src/tools/types.ts +46 -0
- package/src/tools/view-image.ts +89 -0
- package/src/tools/wait.ts +85 -0
- package/src/tui/components/memory-browser.tsx +3 -0
- package/src/tui/event-store.ts +61 -2
- package/src/model/input-token-estimator.ts +0 -25
- package/src/model/moonshot-input-token-estimator.ts +0 -111
- package/src/model/openai-responses-token-estimator.ts +0 -155
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
type ChatEstimatorToolCall = {
|
|
2
|
-
id: string;
|
|
3
|
-
type: "function";
|
|
4
|
-
function: {
|
|
5
|
-
name: string;
|
|
6
|
-
arguments: string;
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
type ChatEstimatorMessage = {
|
|
11
|
-
role: "system" | "user" | "assistant" | "tool";
|
|
12
|
-
content: unknown;
|
|
13
|
-
tool_calls?: ChatEstimatorToolCall[];
|
|
14
|
-
tool_call_id?: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export function responsesPayloadForChatTokenEstimator(
|
|
18
|
-
payload: unknown,
|
|
19
|
-
): Record<string, unknown> {
|
|
20
|
-
const root = requireRecord(payload, "Responses token estimator payload");
|
|
21
|
-
if (!Array.isArray(root.input)) {
|
|
22
|
-
throw new Error("Responses token estimator payload input must be an array.");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const messages: ChatEstimatorMessage[] = [];
|
|
26
|
-
for (const [index, rawItem] of root.input.entries()) {
|
|
27
|
-
const path = `Responses token estimator input[${index}]`;
|
|
28
|
-
const item = requireRecord(rawItem, path);
|
|
29
|
-
const type = requireString(item.type, `${path}.type`);
|
|
30
|
-
if (type === "message") {
|
|
31
|
-
messages.push(toChatMessage(item, path));
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
if (type === "function_call") {
|
|
35
|
-
appendFunctionCall(messages, item, path);
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (type === "function_call_output") {
|
|
39
|
-
messages.push({
|
|
40
|
-
role: "tool",
|
|
41
|
-
tool_call_id: requireString(item.call_id, `${path}.call_id`),
|
|
42
|
-
content: requireString(item.output, `${path}.output`),
|
|
43
|
-
});
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
throw new Error(`${path}.type is unsupported: ${JSON.stringify(type)}.`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
messages,
|
|
51
|
-
...(root.tools === undefined ? {} : { tools: toChatTools(root.tools) }),
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function toChatMessage(
|
|
56
|
-
item: Record<string, unknown>,
|
|
57
|
-
path: string,
|
|
58
|
-
): ChatEstimatorMessage {
|
|
59
|
-
const role = requireString(item.role, `${path}.role`);
|
|
60
|
-
if (role !== "system" && role !== "user" && role !== "assistant") {
|
|
61
|
-
throw new Error(`${path}.role is unsupported: ${JSON.stringify(role)}.`);
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
role,
|
|
65
|
-
content: toChatContent(item.content, `${path}.content`),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function toChatContent(value: unknown, path: string): unknown {
|
|
70
|
-
if (typeof value === "string") {
|
|
71
|
-
return value;
|
|
72
|
-
}
|
|
73
|
-
if (!Array.isArray(value)) {
|
|
74
|
-
throw new Error(`${path} must be a string or an array.`);
|
|
75
|
-
}
|
|
76
|
-
return value.map((rawPart, index) => {
|
|
77
|
-
const partPath = `${path}[${index}]`;
|
|
78
|
-
const part = requireRecord(rawPart, partPath);
|
|
79
|
-
const type = requireString(part.type, `${partPath}.type`);
|
|
80
|
-
if (type === "input_text") {
|
|
81
|
-
return {
|
|
82
|
-
type: "text",
|
|
83
|
-
text: requireString(part.text, `${partPath}.text`),
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
if (type === "input_image") {
|
|
87
|
-
return {
|
|
88
|
-
type: "image_url",
|
|
89
|
-
image_url: {
|
|
90
|
-
url: requireString(part.image_url, `${partPath}.image_url`),
|
|
91
|
-
...(part.detail === undefined
|
|
92
|
-
? {}
|
|
93
|
-
: { detail: requireString(part.detail, `${partPath}.detail`) }),
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
throw new Error(`${partPath}.type is unsupported: ${JSON.stringify(type)}.`);
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function appendFunctionCall(
|
|
102
|
-
messages: ChatEstimatorMessage[],
|
|
103
|
-
item: Record<string, unknown>,
|
|
104
|
-
path: string,
|
|
105
|
-
): void {
|
|
106
|
-
const call: ChatEstimatorToolCall = {
|
|
107
|
-
id: requireString(item.call_id, `${path}.call_id`),
|
|
108
|
-
type: "function",
|
|
109
|
-
function: {
|
|
110
|
-
name: requireString(item.name, `${path}.name`),
|
|
111
|
-
arguments: requireString(item.arguments, `${path}.arguments`),
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
const previous = messages[messages.length - 1];
|
|
115
|
-
if (previous?.role === "assistant") {
|
|
116
|
-
(previous.tool_calls ??= []).push(call);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
messages.push({ role: "assistant", content: null, tool_calls: [call] });
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function toChatTools(value: unknown): Record<string, unknown>[] {
|
|
123
|
-
if (!Array.isArray(value)) {
|
|
124
|
-
throw new Error("Responses token estimator payload tools must be an array.");
|
|
125
|
-
}
|
|
126
|
-
return value.map((rawTool, index) => {
|
|
127
|
-
const path = `Responses token estimator tools[${index}]`;
|
|
128
|
-
const tool = requireRecord(rawTool, path);
|
|
129
|
-
if (tool.type !== "function") {
|
|
130
|
-
throw new Error(`${path}.type must be "function".`);
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
type: "function",
|
|
134
|
-
function: {
|
|
135
|
-
name: requireString(tool.name, `${path}.name`),
|
|
136
|
-
description: requireString(tool.description, `${path}.description`),
|
|
137
|
-
parameters: requireRecord(tool.parameters, `${path}.parameters`),
|
|
138
|
-
},
|
|
139
|
-
};
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function requireRecord(value: unknown, path: string): Record<string, unknown> {
|
|
144
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
145
|
-
throw new Error(`${path} must be an object.`);
|
|
146
|
-
}
|
|
147
|
-
return value as Record<string, unknown>;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function requireString(value: unknown, path: string): string {
|
|
151
|
-
if (typeof value !== "string") {
|
|
152
|
-
throw new Error(`${path} must be a string.`);
|
|
153
|
-
}
|
|
154
|
-
return value;
|
|
155
|
-
}
|