@cubicecho/agent-core 2.2.0 → 2.2.2

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/retry.d.ts CHANGED
@@ -33,8 +33,11 @@ export declare const compact: (tokens: number) => string;
33
33
  * built the entire transcript into a string on every call and threw it away having read nothing
34
34
  * but its `.length` — against a transcript that grows by a turn each turn, and one the SDK is
35
35
  * about to serialise again to send. What the walk misses is JSON's own punctuation and the keys,
36
- * which `ENVELOPE` puts back approximately; the difference is a rounding error against an
37
- * estimate that is already characters over four.
36
+ * which the envelope constants put back one per key and one per content part, rather than one
37
+ * per message, since the keys only some shapes carry and the parts a client appends block by
38
+ * block are most of what a tool-using transcript is made of. What is left is a message's
39
+ * escaping, which is not a constant and is small against an estimate that is already characters
40
+ * over four.
38
41
  *
39
42
  * @param body The request as it will be sent, tools included.
40
43
  */
package/dist/retry.js CHANGED
@@ -29,9 +29,28 @@ export const compact = (tokens) => tokens >= 1000 ? `${(tokens / 1000).toFixed(1
29
29
  const ENVELOPE = 25;
30
30
  /** The same for `{"id":"","type":"function","function":{"name":"","arguments":""}},` in a call. */
31
31
  const CALL_ENVELOPE = 66;
32
+ // `ENVELOPE` is the two keys every message has. These are the three that only some do, and each
33
+ // is the key with its punctuation and the comma after the value it holds — the value's own
34
+ // length is counted where the value is read. Applying `ENVELOPE` alone to these shapes left the
35
+ // keys out, which cost 4.5 tokens on every tool result: the message a tool-using run has most
36
+ // of, and short in the direction that lets an overflow through the guard meant to catch it.
37
+ /** What `"name":"",` costs around a message's name. */
38
+ const NAME_KEY = 10;
39
+ /** The same for `"tool_call_id":"",` around a tool result's call id. */
40
+ const TOOL_CALL_ID_KEY = 18;
41
+ /** The same for `"tool_calls":[]` around the calls; each call's own comma is in `CALL_ENVELOPE`. */
42
+ const TOOL_CALLS_KEY = 15;
43
+ // A content part is an object in the body the same way a message is, and its two keys are in the
44
+ // request exactly as `tool_call_id` was. Charging only `part.text` left them out, which is 6.5
45
+ // tokens per part — short in proportion to how finely the content is split rather than to how
46
+ // much it says, so a transcript a client appends block by block is worst hit.
47
+ /** What `{"type":"text","text":""},` costs around a text part. */
48
+ const TEXT_PART = 26;
49
+ /** The same for `{"type":"refusal","refusal":""},` around a refusal part. */
50
+ const REFUSAL_PART = 32;
32
51
  /** The divisor behind `estimateTokens`, applied here to a character count rather than a string. */
33
52
  const CHARS_PER_TOKEN = 4;
34
- /** How many characters one message is worth, whichever of the shapes its content is in. */
53
+ /** How many characters one message is worth: its keys, and its content in whichever shape. */
35
54
  function messageChars(message) {
36
55
  let chars = message.role.length + ENVELOPE;
37
56
  const { content } = message;
@@ -40,22 +59,26 @@ function messageChars(message) {
40
59
  else if (Array.isArray(content))
41
60
  for (const part of content) {
42
61
  // Text and refusal parts carry their own strings; an image or an audio part carries a URL
43
- // or a blob, and neither is priced by its length anyway.
62
+ // or a blob, and neither is priced by its length anyway — a vision model does not charge
63
+ // an image by its base64 length, so counting the data URL would overshoot by more than
64
+ // leaving the part out undershoots.
44
65
  if (part.type === "text")
45
- chars += part.text.length;
66
+ chars += TEXT_PART + part.text.length;
46
67
  else if (part.type === "refusal")
47
- chars += part.refusal.length;
68
+ chars += REFUSAL_PART + part.refusal.length;
48
69
  }
49
70
  if ("name" in message && typeof message.name === "string")
50
- chars += message.name.length;
71
+ chars += NAME_KEY + message.name.length;
51
72
  if ("tool_call_id" in message && typeof message.tool_call_id === "string")
52
- chars += message.tool_call_id.length;
53
- if ("tool_calls" in message && Array.isArray(message.tool_calls))
73
+ chars += TOOL_CALL_ID_KEY + message.tool_call_id.length;
74
+ if ("tool_calls" in message && Array.isArray(message.tool_calls)) {
75
+ chars += TOOL_CALLS_KEY;
54
76
  for (const call of message.tool_calls) {
55
77
  chars += CALL_ENVELOPE + call.id.length;
56
78
  if (call.type === "function")
57
79
  chars += call.function.name.length + call.function.arguments.length;
58
80
  }
81
+ }
59
82
  return chars;
60
83
  }
61
84
  /**
@@ -92,8 +115,11 @@ function toolsCost(tools) {
92
115
  * built the entire transcript into a string on every call and threw it away having read nothing
93
116
  * but its `.length` — against a transcript that grows by a turn each turn, and one the SDK is
94
117
  * about to serialise again to send. What the walk misses is JSON's own punctuation and the keys,
95
- * which `ENVELOPE` puts back approximately; the difference is a rounding error against an
96
- * estimate that is already characters over four.
118
+ * which the envelope constants put back one per key and one per content part, rather than one
119
+ * per message, since the keys only some shapes carry and the parts a client appends block by
120
+ * block are most of what a tool-using transcript is made of. What is left is a message's
121
+ * escaping, which is not a constant and is small against an estimate that is already characters
122
+ * over four.
97
123
  *
98
124
  * @param body The request as it will be sent, tools included.
99
125
  */
@@ -12,6 +12,11 @@ export interface SideTaskOptions {
12
12
  /**
13
13
  * Told what was given up on, the same way `runTurn` and `negotiate` tell a caller.
14
14
  *
15
+ * The one notice `ask` raises itself opens with the model's name, as `negotiate`'s do for the
16
+ * refusals that are the model's: what it announces is latched on the (endpoint, model) pair,
17
+ * so on a consumer reaching several models through one base URL the name is the only thing
18
+ * separating one announcement from the next.
19
+ *
15
20
  * There is no default, and nothing is printed without one. A library that writes to the
16
21
  * console decides for its consumer where operator text goes — which a server embedding this
17
22
  * cannot then route to its own logger, attach to the run it belongs to, or silence in tests.
package/dist/side-task.js CHANGED
@@ -125,7 +125,7 @@ export async function ask(config, model, system, user, { maxTokens = 512, temper
125
125
  // does not offer as `none`.
126
126
  if (!hints || !rejectedTheRequest(error))
127
127
  throw error;
128
- onNotice?.("server rejected the no-thinking hints; retrying without them");
128
+ onNotice?.(`${model} rejected the no-thinking hints; retrying without them`);
129
129
  noHints.add(key);
130
130
  response = await attempt(false);
131
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cubicecho/agent-core",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "The endpoint-agnostic half of an OpenAI-compatible agent loop: tool-schema compatibility, on-demand tool loading, one-shot side tasks, run events, and a pooled client.",
5
5
  "keywords": [
6
6
  "openai",