@bastani/pi-ai 0.9.43 → 0.9.44-alpha.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.
Files changed (77) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/api/anthropic-messages.d.ts.map +1 -1
  3. package/dist/api/anthropic-messages.js +45 -58
  4. package/dist/api/anthropic-messages.js.map +1 -1
  5. package/dist/api/azure-openai-responses.d.ts.map +1 -1
  6. package/dist/api/azure-openai-responses.js +0 -6
  7. package/dist/api/azure-openai-responses.js.map +1 -1
  8. package/dist/api/bedrock-converse-stream.d.ts.map +1 -1
  9. package/dist/api/bedrock-converse-stream.js +71 -78
  10. package/dist/api/bedrock-converse-stream.js.map +1 -1
  11. package/dist/api/constrained-sampling.d.ts +11 -1
  12. package/dist/api/constrained-sampling.d.ts.map +1 -1
  13. package/dist/api/constrained-sampling.js +33 -18
  14. package/dist/api/constrained-sampling.js.map +1 -1
  15. package/dist/api/google-generative-ai.d.ts.map +1 -1
  16. package/dist/api/google-generative-ai.js +0 -6
  17. package/dist/api/google-generative-ai.js.map +1 -1
  18. package/dist/api/google-shared.d.ts +2 -1
  19. package/dist/api/google-shared.d.ts.map +1 -1
  20. package/dist/api/google-shared.js +57 -2
  21. package/dist/api/google-shared.js.map +1 -1
  22. package/dist/api/google-vertex.d.ts.map +1 -1
  23. package/dist/api/google-vertex.js +0 -6
  24. package/dist/api/google-vertex.js.map +1 -1
  25. package/dist/api/mistral-conversations.d.ts.map +1 -1
  26. package/dist/api/mistral-conversations.js +17 -44
  27. package/dist/api/mistral-conversations.js.map +1 -1
  28. package/dist/api/openai-codex-responses.d.ts.map +1 -1
  29. package/dist/api/openai-codex-responses.js +0 -5
  30. package/dist/api/openai-codex-responses.js.map +1 -1
  31. package/dist/api/openai-completions.d.ts.map +1 -1
  32. package/dist/api/openai-completions.js +34 -53
  33. package/dist/api/openai-completions.js.map +1 -1
  34. package/dist/api/openai-responses-shared.d.ts.map +1 -1
  35. package/dist/api/openai-responses-shared.js +58 -57
  36. package/dist/api/openai-responses-shared.js.map +1 -1
  37. package/dist/api/openai-responses.d.ts.map +1 -1
  38. package/dist/api/openai-responses.js +0 -6
  39. package/dist/api/openai-responses.js.map +1 -1
  40. package/dist/api/pi-messages.d.ts +2 -0
  41. package/dist/api/pi-messages.d.ts.map +1 -1
  42. package/dist/api/pi-messages.js +15 -9
  43. package/dist/api/pi-messages.js.map +1 -1
  44. package/dist/index.d.ts +1 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +1 -0
  47. package/dist/index.js.map +1 -1
  48. package/dist/providers/data/.manifest.json +1 -1
  49. package/dist/providers/data/kimi-coding.json +1 -1
  50. package/dist/providers/data/moonshotai-cn.json +1 -1
  51. package/dist/providers/data/moonshotai.json +1 -1
  52. package/dist/providers/data/opencode-go.json +1 -1
  53. package/dist/providers/data/openrouter.json +1 -1
  54. package/dist/providers/data/vercel-ai-gateway.json +1 -1
  55. package/dist/providers/faux.d.ts.map +1 -1
  56. package/dist/providers/faux.js +7 -2
  57. package/dist/providers/faux.js.map +1 -1
  58. package/dist/providers/radius-config.d.ts.map +1 -1
  59. package/dist/providers/radius-config.js +2 -1
  60. package/dist/providers/radius-config.js.map +1 -1
  61. package/dist/types.js.map +1 -1
  62. package/dist/utils/error-body.d.ts.map +1 -1
  63. package/dist/utils/error-body.js +2 -1
  64. package/dist/utils/error-body.js.map +1 -1
  65. package/dist/utils/streaming-json.d.ts +84 -0
  66. package/dist/utils/streaming-json.d.ts.map +1 -0
  67. package/dist/utils/streaming-json.js +513 -0
  68. package/dist/utils/streaming-json.js.map +1 -0
  69. package/dist/utils/text.d.ts +7 -0
  70. package/dist/utils/text.d.ts.map +1 -1
  71. package/dist/utils/text.js +9 -0
  72. package/dist/utils/text.js.map +1 -1
  73. package/dist/utils/version.d.ts +1 -1
  74. package/dist/utils/version.d.ts.map +1 -1
  75. package/dist/utils/version.js +1 -1
  76. package/dist/utils/version.js.map +1 -1
  77. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streaming-json.js","sourceRoot":"","sources":["../../src/utils/streaming-json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAmDzD,yEAAyE;AACzE,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAE9B,MAAM,SAAS,GAAS,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AACzC,8GAA8G;AAC9G,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAC/B,mGAAmG;AACnG,MAAM,yBAAyB,GAAG,EAAE,CAAC;AACrC,MAAM,MAAM,GAAG,+CAA+C,CAAC;AAC/D,MAAM,8BAA8B,GAAG,yCAAyC,CAAC;AACjF,MAAM,QAAQ,GAAmC;IAChD,CAAC,MAAM,EAAE,IAAI,CAAC;IACd,CAAC,OAAO,EAAE,KAAK,CAAC;IAChB,CAAC,MAAM,EAAE,IAAI,CAAC;CACd,CAAC;AAEF,MAAM,KAAK,GAAG,IAAI,CAAC;AACnB,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB,yFAAyF;AACzF,MAAM,OAAO,mBAAmB;IAC/B,KAAK,GAA0B,SAAS,CAAC;IACzC,KAAK,GAAG,KAAK,CAAC;IACL,MAAM,GAAY,EAAE,CAAC;IAC9B,OAAO,GAA2B,SAAS,CAAC;IAC5C,OAAO,GAAG,EAAE,CAAC;IACb,WAAW,GAAqB,SAAS,CAAC;IAC1C,0EAA0E;IAC1E,SAAS,GAAG,CAAC,CAAC;IACd,OAAO,GAAG,CAAC,CAAC;IACZ,MAAM,GAAG,KAAK,CAAC;IACf,SAAS,GAA0B,SAAS,CAAC;IAC7C,uCAAuC;IACvC,QAAQ,GAAiB,EAAE,CAAC;IAE5B;;OAEG;IACH,MAAM,CAAC,IAAY;QA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AAK,CAAC,CAAC;IAC5D,OAAO,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,OAAO,CAAC,SAAwB,EAAE,IAAU,EAAE,KAAgB;IACtE,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS;QAAG,SAAyB,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;SACvE,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ;QAAE,SAAS,CAAC,SAAyC,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACxG,CAAC;AAED,SAAS,SAAS,CAAC,OAAqC,EAAE,GAAW,EAAE,KAAgB;IACtF,gFAAgF;IAChF,IAAI,GAAG,KAAK,WAAW,EAAE,CAAC;QACzB,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;IACtG,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC;AACF,CAAC","sourcesContent":["/**\n * Incremental, tolerant parsing of JSON text that arrives in pieces, such as streamed tool-call arguments.\n *\n * `StreamingJsonParser.append()` reads each piece once, so a stream costs time and memory linear in its length, and\n * `snapshot()` returns the value of the text read so far. Snapshots are plain JSON values and never change once\n * returned: the parser copies the containers that are still open (the \"open path\") into every new snapshot and shares\n * completed containers and strings. The rules for incomplete text follow `parseStreamingJson()`:\n *\n * - An unterminated string shows the characters read so far; an unterminated escape is held back until complete.\n * - An unterminated container shows the members and elements read so far.\n * - A member whose key or value has not started is omitted.\n * - An unterminated literal shows its value once it is a prefix of `true`, `false` or `null`; an unterminated number\n * shows its value when the digits read so far form a number (an exponent without digits is ignored).\n *\n * Malformed text is read leniently, the way `repairJson()` and `parseStreamingJson()` treat it: raw control characters\n * in strings are kept, an invalid escape such as `\\d` stays literal text, missing commas and colons are tolerated,\n * values in invalid positions and unknown words are dropped, and text after the root value is ignored. The parser never\n * throws. Callers that need the exact value of the finished text parse it once, e.g. with `parseToolCallArguments()`.\n *\n * Differences from `parseStreamingJson()` on incomplete text: trailing whitespace inside an unterminated string is\n * kept (it was trimmed), a string that contains a raw control character or an invalid escape stays visible while it\n * streams (it was dropped until the document was complete), and `NaN` and `Infinity` words are dropped.\n *\n * `append()` also returns the changes the piece made, for a writer that keeps its own copy of the value and applies\n * them instead of re-assigning snapshots: `set` when a key, an array item or a finished value appears (a new string is\n * set once with its first text, a container empty), `append` when the piece extended an open string. Unterminated\n * numbers and literals are not reported until they end. A container nested more than 32 levels deep is reported as one\n * `set` of its whole value when it closes, so paths stay short.\n *\n * Cost: copying the open path costs its member and element count. Each `append()` earns copy credit proportional to its\n * length plus a constant; `snapshot()` spends it and returns the previous snapshot while the open path costs more than\n * the credit. So a document that keeps a very large container open (thousands of elements) shows a preview that lags\n * a little behind the text, and no input makes the total work grow faster than the text.\n */\n\nimport type { JsonValue, ToolCall } from \"../types.ts\";\nimport { parseToolCallArguments } from \"./json-parse.ts\";\n\ntype JsonContainer = { [key: string]: JsonValue } | JsonValue[];\n\n/** Where a value sits in its parent; absent for a value in an invalid position, which is read but dropped. */\ntype Slot =\n\t| { readonly kind: \"root\" }\n\t| { readonly kind: \"member\"; readonly key: string }\n\t| { readonly kind: \"element\"; readonly index: number };\n\n/** A path from the root value: member keys and array indices. */\nexport type JsonPath = readonly (string | number)[];\n\n/** One change a piece of text made to the value; see the module comment. */\nexport type JsonChange =\n\t| { readonly kind: \"set\"; readonly path: JsonPath; readonly value: JsonValue }\n\t| { readonly kind: \"append\"; readonly path: JsonPath; readonly text: string };\n\n/** A change still being extended by the piece being read. */\ntype OpenChange =\n\t| { kind: \"set\"; readonly path: JsonPath; value: JsonValue }\n\t| { kind: \"append\"; readonly path: JsonPath; text: string };\n\n/** An open object or array. Its `container` is never handed out while open; snapshots get copies. */\ntype Frame = {\n\treadonly container: JsonContainer;\n\treadonly slot: Slot | undefined;\n\t/** Where the container sits, when its changes are reported. */\n\treadonly path: JsonPath | undefined;\n\t/** Whether changes inside it are reported; when not, its whole value is reported as it closes. */\n\treadonly reportsInside: boolean;\n\t/** Members or elements; what a copy of the container costs. */\n\tsize: number;\n\t/** Objects: the key read last, where the member value goes. */\n\tkey: string | undefined;\n\tphase: \"key\" | \"colon\" | \"value\" | \"comma\";\n};\n\n/** An unterminated string. */\ntype OpenString = {\n\treadonly target: \"key\" | \"value\";\n\treadonly slot: Slot | undefined;\n\ttext: string;\n\t/** Escape read so far: \"\" for none, otherwise a backslash and up to five more characters. */\n\tescape: string;\n\t/** Where a value string sits, when its changes are reported. */\n\treadonly path: JsonPath | undefined;\n\t/** The change this string extends, while it is the newest change of the piece. */\n\tchange: OpenChange | undefined;\n};\n\n// Changes are reported at most this deep, so a path costs O(1) to build.\nconst MAX_REPORTED_DEPTH = 32;\n\nconst ROOT_SLOT: Slot = { kind: \"root\" };\n// Copy credit per append and per appended character. The floor keeps small documents fresh at every snapshot.\nconst CREDIT_PER_APPEND = 256;\nconst CREDIT_PER_CHARACTER = 8;\n// An unterminated number longer than this is not shown until it ends, so `snapshot()` stays cheap.\nconst MAX_PENDING_SCALAR_LENGTH = 64;\nconst NUMBER = /^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?$/;\nconst NUMBER_WITHOUT_EXPONENT_DIGITS = /^(-?(?:0|[1-9]\\d*)(?:\\.\\d+)?)[eE][+-]?$/;\nconst LITERALS: readonly [string, JsonValue][] = [\n\t[\"true\", true],\n\t[\"false\", false],\n\t[\"null\", null],\n];\n\nconst QUOTE = 0x22;\nconst BACKSLASH = 0x5c;\n\n/** Incremental, tolerant JSON parser; see the module comment for its rules and costs. */\nexport class StreamingJsonParser {\n\t#root: JsonValue | undefined = undefined;\n\t#done = false;\n\treadonly #stack: Frame[] = [];\n\t#string: OpenString | undefined = undefined;\n\t#scalar = \"\";\n\t#scalarSlot: Slot | undefined = undefined;\n\t/** Sum of `size + 1` over the open path: what a fresh snapshot copies. */\n\t#pathCost = 0;\n\t#credit = 0;\n\t#dirty = false;\n\t#snapshot: JsonValue | undefined = undefined;\n\t/** Changes of the piece being read. */\n\t#changes: OpenChange[] = [];\n\n\t/**\n\t * Read the next piece of text; returns the changes it made, in order. Costs time linear in `text.length`.\n\t */\n\tappend(text: string): readonly JsonChange[] {\n\t\tthis.#credit += CREDIT_PER_APPEND + CREDIT_PER_CHARACTER * text.length;\n\t\tthis.#changes = [];\n\t\tif (this.#string !== undefined) this.#string.change = undefined;\n\t\tlet index = 0;\n\t\twhile (index < text.length && !this.#done) {\n\t\t\tconst open = this.#string;\n\t\t\tif (open !== undefined) index = this.#readString(open, text, index);\n\t\t\telse if (this.#scalar !== \"\") index = this.#readScalar(text, index);\n\t\t\telse this.#structural(text[index++]!);\n\t\t}\n\t\treturn this.#changes;\n\t}\n\n\t/**\n\t * The value of the text read so far: `undefined` before a value starts, otherwise a plain JSON value that never\n\t * changes afterwards. Returns the previous snapshot while the text read since did not change the value, or while a\n\t * fresh copy of the open path is not yet paid for (see the module comment).\n\t */\n\tsnapshot(): JsonValue | undefined {\n\t\tif (!this.#dirty) return this.#snapshot;\n\t\tconst pending = this.#pendingScalar();\n\t\tconst cost = this.#pathCost + (pending === undefined ? 0 : 1);\n\t\tif (cost > this.#credit) return this.#snapshot;\n\t\tthis.#credit -= cost;\n\t\tthis.#dirty = false;\n\t\tthis.#snapshot = this.#copyOpenPath(pending);\n\t\treturn this.#snapshot;\n\t}\n\n\t/** Read string characters from `start` until the string ends or the text does; returns the next index. */\n\t#readString(open: OpenString, text: string, start: number): number {\n\t\tlet runStart = start;\n\t\tfor (let index = start; index < text.length; index++) {\n\t\t\tconst code = text.charCodeAt(index);\n\t\t\tif (open.escape !== \"\") {\n\t\t\t\tif (this.#continueEscape(open, text[index]!)) {\n\t\t\t\t\trunStart = index + 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// Not part of the escape: read it as a normal string character below.\n\t\t\t\trunStart = index;\n\t\t\t}\n\t\t\tif (code === QUOTE) {\n\t\t\t\tif (index > runStart) this.#appendString(open, text.slice(runStart, index));\n\t\t\t\tthis.#endString(open);\n\t\t\t\treturn index + 1;\n\t\t\t}\n\t\t\tif (code === BACKSLASH) {\n\t\t\t\tif (index > runStart) this.#appendString(open, text.slice(runStart, index));\n\t\t\t\topen.escape = \"\\\\\";\n\t\t\t\trunStart = index + 1;\n\t\t\t}\n\t\t}\n\t\tif (text.length > runStart) this.#appendString(open, text.slice(runStart));\n\t\treturn text.length;\n\t}\n\n\t/** Read number or literal characters from `start` up to the next delimiter; returns the delimiter's index. */\n\t#readScalar(text: string, start: number): number {\n\t\tlet end = start;\n\t\twhile (end < text.length && !isDelimiter(text[end]!)) end++;\n\t\tif (end > start) {\n\t\t\tthis.#scalar += text.slice(start, end);\n\t\t\tif (this.#scalarSlot !== undefined) this.#dirty = true;\n\t\t}\n\t\tif (end < text.length) this.#endScalar();\n\t\treturn end;\n\t}\n\n\t/** Handle one character outside strings. */\n\t#structural(char: string): void {\n\t\tswitch (char) {\n\t\t\tcase \" \":\n\t\t\tcase \"\\t\":\n\t\t\tcase \"\\n\":\n\t\t\tcase \"\\r\":\n\t\t\t\treturn;\n\t\t\tcase '\"':\n\t\t\t\tthis.#startString();\n\t\t\t\treturn;\n\t\t\tcase \"{\":\n\t\t\tcase \"[\":\n\t\t\t\tthis.#openContainer(char === \"{\" ? {} : []);\n\t\t\t\treturn;\n\t\t\tcase \"}\":\n\t\t\tcase \"]\":\n\t\t\t\tthis.#closeContainer();\n\t\t\t\treturn;\n\t\t\tcase \":\": {\n\t\t\t\tconst frame = this.#stack.at(-1);\n\t\t\t\tif (frame !== undefined && !Array.isArray(frame.container) && frame.phase === \"colon\")\n\t\t\t\t\tframe.phase = \"value\";\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \",\": {\n\t\t\t\tconst frame = this.#stack.at(-1);\n\t\t\t\tif (frame !== undefined) frame.phase = Array.isArray(frame.container) ? \"value\" : \"key\";\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tthis.#scalar = char;\n\t\t\t\tthis.#scalarSlot = this.#valueSlot();\n\t\t\t\tif (this.#scalarSlot !== undefined) this.#dirty = true;\n\t\t}\n\t}\n\n\t/** Where a value starting now goes, or `undefined` when this position takes no value. */\n\t#valueSlot(): Slot | undefined {\n\t\tconst frame = this.#stack.at(-1);\n\t\tif (frame === undefined) return this.#root === undefined ? ROOT_SLOT : undefined;\n\t\tif (Array.isArray(frame.container)) return { kind: \"element\", index: frame.container.length };\n\t\t// A missing colon is tolerated: `{\"a\" 1}` reads as `{\"a\": 1}`.\n\t\tif ((frame.phase === \"value\" || frame.phase === \"colon\") && frame.key !== undefined) {\n\t\t\treturn { kind: \"member\", key: frame.key };\n\t\t}\n\t\treturn undefined;\n\t}\n\n\t#startString(): void {\n\t\tconst frame = this.#stack.at(-1);\n\t\t// A missing comma is tolerated: `{\"a\": 1 \"b\": 2}` reads the second member.\n\t\tif (\n\t\t\tframe !== undefined &&\n\t\t\t!Array.isArray(frame.container) &&\n\t\t\t(frame.phase === \"key\" || frame.phase === \"comma\")\n\t\t) {\n\t\t\tthis.#string = { target: \"key\", slot: undefined, text: \"\", escape: \"\", path: undefined, change: undefined };\n\t\t\treturn;\n\t\t}\n\t\tconst slot = this.#valueSlot();\n\t\tconst path = this.#reportedPath(slot);\n\t\tthis.#string = { target: \"value\", slot, text: \"\", escape: \"\", path, change: undefined };\n\t\tthis.#place(slot, \"\");\n\t\tif (path !== undefined) this.#string.change = this.#report({ kind: \"set\", path, value: \"\" });\n\t}\n\n\t/** The path of a value at `slot` in the innermost open container, when its changes are reported. */\n\t#reportedPath(slot: Slot | undefined): JsonPath | undefined {\n\t\tif (slot === undefined) return undefined;\n\t\tif (slot.kind === \"root\") return [];\n\t\tconst frame = this.#stack.at(-1)!;\n\t\tif (!frame.reportsInside) return undefined;\n\t\treturn [...frame.path!, slot.kind === \"member\" ? slot.key : slot.index];\n\t}\n\n\t#report(change: OpenChange): OpenChange {\n\t\tthis.#changes.push(change);\n\t\treturn change;\n\t}\n\n\t/** Continue an escape with `char`; returns false when `char` is not part of it and must be read normally. */\n\t#continueEscape(open: OpenString, char: string): boolean {\n\t\tif (open.escape === \"\\\\\") {\n\t\t\tconst decoded = SIMPLE_ESCAPES[char];\n\t\t\tif (decoded !== undefined) {\n\t\t\t\topen.escape = \"\";\n\t\t\t\tthis.#appendString(open, decoded);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (char === \"u\") {\n\t\t\t\topen.escape = \"\\\\u\";\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\t// Invalid escape: keep the backslash as text and read the character normally, as repairJson() does.\n\t\t\topen.escape = \"\";\n\t\t\tthis.#appendString(open, \"\\\\\");\n\t\t\treturn false;\n\t\t}\n\t\tif (isHexDigit(char)) {\n\t\t\topen.escape += char;\n\t\t\tif (open.escape.length < 6) return true;\n\t\t\tconst decoded = String.fromCharCode(Number.parseInt(open.escape.slice(2), 16));\n\t\t\topen.escape = \"\";\n\t\t\tthis.#appendString(open, decoded);\n\t\t\treturn true;\n\t\t}\n\t\t// `\\u` without four hex digits: keep it as text and read the character normally, as repairJson() does.\n\t\tconst literal = open.escape;\n\t\topen.escape = \"\";\n\t\tthis.#appendString(open, literal);\n\t\treturn false;\n\t}\n\n\t#appendString(open: OpenString, text: string): void {\n\t\topen.text += text;\n\t\tif (open.target !== \"value\") return;\n\t\tthis.#place(open.slot, open.text);\n\t\tif (open.path === undefined) return;\n\t\t// Extend this string's newest change while nothing came after it; otherwise report an append.\n\t\tconst change = open.change;\n\t\tif (change !== undefined && this.#changes.at(-1) === change) {\n\t\t\tif (change.kind === \"set\") change.value = (change.value as string) + text;\n\t\t\telse change.text += text;\n\t\t\treturn;\n\t\t}\n\t\topen.change = this.#report({ kind: \"append\", path: open.path, text });\n\t}\n\n\t#endString(open: OpenString): void {\n\t\tthis.#string = undefined;\n\t\tconst frame = this.#stack.at(-1);\n\t\tif (open.target === \"key\") {\n\t\t\tif (frame === undefined) return;\n\t\t\tframe.key = open.text;\n\t\t\tframe.phase = \"colon\";\n\t\t\treturn;\n\t\t}\n\t\tthis.#valueEnded(frame);\n\t}\n\n\t#endScalar(): void {\n\t\tconst token = this.#scalar;\n\t\tconst slot = this.#scalarSlot;\n\t\tthis.#scalar = \"\";\n\t\tthis.#scalarSlot = undefined;\n\t\tconst value = scalarValue(token);\n\t\tif (value !== undefined) {\n\t\t\tthis.#place(slot, value);\n\t\t\tconst path = this.#reportedPath(slot);\n\t\t\tif (path !== undefined) this.#report({ kind: \"set\", path, value });\n\t\t}\n\t\tthis.#valueEnded(this.#stack.at(-1));\n\t}\n\n\t/** The value of the unterminated scalar at the end of the text, if it shows. */\n\t#pendingScalar(): { readonly slot: Slot; readonly value: JsonValue } | undefined {\n\t\tconst slot = this.#scalarSlot;\n\t\tconst token = this.#scalar;\n\t\tif (slot === undefined || token === \"\" || token.length > MAX_PENDING_SCALAR_LENGTH) return undefined;\n\t\tconst value = pendingScalarValue(token);\n\t\treturn value === undefined ? undefined : { slot, value };\n\t}\n\n\t#openContainer(container: JsonContainer): void {\n\t\tconst slot = this.#valueSlot();\n\t\tconst path = this.#reportedPath(slot);\n\t\tthis.#place(slot, container);\n\t\tthis.#stack.push({\n\t\t\tcontainer,\n\t\t\tslot,\n\t\t\tpath,\n\t\t\treportsInside: path !== undefined && path.length < MAX_REPORTED_DEPTH,\n\t\t\tsize: 0,\n\t\t\tkey: undefined,\n\t\t\tphase: Array.isArray(container) ? \"value\" : \"key\",\n\t\t});\n\t\tthis.#pathCost += 1;\n\t\tthis.#dirty = true;\n\t\t// A fresh container: the working one keeps changing, and a change never does.\n\t\tif (path !== undefined) this.#report({ kind: \"set\", path, value: Array.isArray(container) ? [] : {} });\n\t}\n\n\t#closeContainer(): void {\n\t\tconst frame = this.#stack.pop();\n\t\t// A stray closer outside any container is ignored.\n\t\tif (frame === undefined) return;\n\t\tthis.#pathCost -= frame.size + 1;\n\t\tthis.#dirty = true;\n\t\t// Too deep to report inside: the whole value, final now that it is closed.\n\t\tif (frame.path !== undefined && !frame.reportsInside) {\n\t\t\tthis.#report({ kind: \"set\", path: frame.path, value: frame.container });\n\t\t}\n\t\tthis.#valueEnded(this.#stack.at(-1));\n\t}\n\n\t/** A value in `frame`, or the root value when there is no frame, has ended. */\n\t#valueEnded(frame: Frame | undefined): void {\n\t\tif (frame === undefined) {\n\t\t\t// Text after the root value is ignored, but only once a root value exists.\n\t\t\tif (this.#root !== undefined) this.#done = true;\n\t\t\treturn;\n\t\t}\n\t\tframe.phase = \"comma\";\n\t}\n\n\t/** Set the value at `slot` in the open path; nothing for a value in an invalid position. */\n\t#place(slot: Slot | undefined, value: JsonValue): void {\n\t\tif (slot === undefined) return;\n\t\tthis.#dirty = true;\n\t\tif (slot.kind === \"root\") {\n\t\t\tthis.#root = value;\n\t\t\treturn;\n\t\t}\n\t\tconst frame = this.#stack.at(-1)!;\n\t\tif (slot.kind === \"element\") {\n\t\t\tconst elements = frame.container as JsonValue[];\n\t\t\tif (slot.index === elements.length) {\n\t\t\t\tframe.size++;\n\t\t\t\tthis.#pathCost++;\n\t\t\t}\n\t\t\telements[slot.index] = value;\n\t\t\treturn;\n\t\t}\n\t\tconst members = frame.container as { [key: string]: JsonValue };\n\t\tif (!Object.hasOwn(members, slot.key)) {\n\t\t\tframe.size++;\n\t\t\tthis.#pathCost++;\n\t\t}\n\t\tsetMember(members, slot.key, value);\n\t}\n\n\t/** A fresh snapshot: copies of the open containers, innermost first, each holding the copy of its open child. */\n\t#copyOpenPath(pending: { readonly slot: Slot; readonly value: JsonValue } | undefined): JsonValue | undefined {\n\t\tif (this.#stack.length === 0) return pending?.slot.kind === \"root\" ? pending.value : this.#root;\n\t\tlet child: JsonValue | undefined;\n\t\tlet childSlot: Slot | undefined;\n\t\tfor (let depth = this.#stack.length - 1; depth >= 0; depth--) {\n\t\t\tconst frame = this.#stack[depth]!;\n\t\t\tconst copy: JsonContainer = Array.isArray(frame.container) ? frame.container.slice() : { ...frame.container };\n\t\t\tif (depth === this.#stack.length - 1 && pending !== undefined) setSlot(copy, pending.slot, pending.value);\n\t\t\tif (child !== undefined && childSlot !== undefined) setSlot(copy, childSlot, child);\n\t\t\tchild = copy;\n\t\t\tchildSlot = frame.slot;\n\t\t}\n\t\t// The outermost open container is the root unless it sits in an invalid position.\n\t\treturn childSlot?.kind === \"root\" ? child : this.#root;\n\t}\n}\n\n/**\n * The arguments of one streaming tool call: the raw text, for the one full parse when the call ends, and a\n * `StreamingJsonParser` for the partial arguments in between. Providers keep one per call in their own stream state,\n * never on the content block, so the raw text never reaches partial messages or transcripts.\n */\nexport class ToolCallArgumentsStream {\n\t#text = \"\";\n\t#parser = new StreamingJsonParser();\n\t#snapshot: JsonValue | undefined = undefined;\n\t#arguments: ToolCall[\"arguments\"] = {};\n\n\t/** The raw argument text received so far. */\n\tget text(): string {\n\t\treturn this.#text;\n\t}\n\n\t/** Append a piece of argument text; returns the partial arguments, a new object whenever they changed. */\n\tappend(delta: string): ToolCall[\"arguments\"] {\n\t\tthis.#text += delta;\n\t\tthis.#parser.append(delta);\n\t\treturn this.#partial();\n\t}\n\n\t/**\n\t * Take the provider's complete argument text. When it continues the text so far, returns the missing piece as\n\t * `delta`; otherwise starts over with `text`. Either way returns the partial arguments of `text`.\n\t */\n\treplace(text: string): { readonly delta: string | undefined; readonly arguments: ToolCall[\"arguments\"] } {\n\t\tif (text.startsWith(this.#text)) {\n\t\t\tconst delta = text.slice(this.#text.length);\n\t\t\treturn { delta, arguments: delta === \"\" ? this.#partial() : this.append(delta) };\n\t\t}\n\t\tthis.#text = \"\";\n\t\tthis.#parser = new StreamingJsonParser();\n\t\treturn { delta: undefined, arguments: this.append(text) };\n\t}\n\n\t/** The final arguments: one full parse of the complete text, which reports malformed arguments. */\n\tfinish(): Pick<ToolCall, \"arguments\" | \"argumentsError\"> {\n\t\treturn parseToolCallArguments(this.#text);\n\t}\n\n\t#partial(): ToolCall[\"arguments\"] {\n\t\tconst snapshot = this.#parser.snapshot();\n\t\tif (snapshot === this.#snapshot) return this.#arguments;\n\t\tthis.#snapshot = snapshot;\n\t\t// Tool arguments are an object; any other partial value shows as no arguments yet.\n\t\tthis.#arguments =\n\t\t\ttypeof snapshot === \"object\" && snapshot !== null && !Array.isArray(snapshot)\n\t\t\t\t? (snapshot as ToolCall[\"arguments\"])\n\t\t\t\t: {};\n\t\treturn this.#arguments;\n\t}\n}\n\nconst SIMPLE_ESCAPES: Readonly<Record<string, string>> = {\n\t'\"': '\"',\n\t\"\\\\\": \"\\\\\",\n\t\"/\": \"/\",\n\tb: \"\\b\",\n\tf: \"\\f\",\n\tn: \"\\n\",\n\tr: \"\\r\",\n\tt: \"\\t\",\n};\n\nfunction isDelimiter(char: string): boolean {\n\treturn (\n\t\tchar === \" \" ||\n\t\tchar === \"\\t\" ||\n\t\tchar === \"\\n\" ||\n\t\tchar === \"\\r\" ||\n\t\tchar === \",\" ||\n\t\tchar === \":\" ||\n\t\tchar === \"{\" ||\n\t\tchar === \"}\" ||\n\t\tchar === \"[\" ||\n\t\tchar === \"]\" ||\n\t\tchar === '\"'\n\t);\n}\n\nfunction isHexDigit(char: string): boolean {\n\treturn (char >= \"0\" && char <= \"9\") || (char >= \"a\" && char <= \"f\") || (char >= \"A\" && char <= \"F\");\n}\n\n/** The value of a complete number or literal token; `undefined` for anything else, which is dropped. */\nfunction scalarValue(token: string): JsonValue | undefined {\n\tfor (const [literal, value] of LITERALS) if (token === literal) return value;\n\treturn NUMBER.test(token) ? Number(token) : undefined;\n}\n\n/** The value an unterminated number or literal token shows. */\nfunction pendingScalarValue(token: string): JsonValue | undefined {\n\tfor (const [literal, value] of LITERALS) if (literal.startsWith(token)) return value;\n\tif (NUMBER.test(token)) return Number(token);\n\tconst mantissa = NUMBER_WITHOUT_EXPONENT_DIGITS.exec(token);\n\treturn mantissa === null ? undefined : Number(mantissa[1]);\n}\n\nfunction setSlot(container: JsonContainer, slot: Slot, value: JsonValue): void {\n\tif (slot.kind === \"element\") (container as JsonValue[])[slot.index] = value;\n\telse if (slot.kind === \"member\") setMember(container as { [key: string]: JsonValue }, slot.key, value);\n}\n\nfunction setMember(members: { [key: string]: JsonValue }, key: string, value: JsonValue): void {\n\t// `__proto__` must become an own member, as in JSON.parse(), not the prototype.\n\tif (key === \"__proto__\") {\n\t\tObject.defineProperty(members, key, { value, writable: true, enumerable: true, configurable: true });\n\t} else {\n\t\tmembers[key] = value;\n\t}\n}\n"]}
@@ -10,5 +10,12 @@ export declare function getSystemMessageText(message: SystemMessage): string;
10
10
  * This framing is request-time only and may change between versions.
11
11
  */
12
12
  export declare function renderSystemMessageUpdate(message: SystemMessage): string;
13
+ /**
14
+ * `text.slice(start, end)` as a string of its own. V8 represents a slice of 13 or more characters as a view that keeps
15
+ * all of `text` alive, so a short excerpt kept from a large text (a 500-character error message cut from a megabyte
16
+ * response body) would keep the whole text alive as long as the excerpt lives. Appending a character and slicing it off
17
+ * again makes V8 copy just the slice.
18
+ */
19
+ export declare function ownedSlice(text: string, start: number, end?: number): string;
13
20
  export {};
14
21
  //# sourceMappingURL=text.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/utils/text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAExH,KAAK,OAAO,GAAG,WAAW,GAAG,YAAY,GAAG,eAAe,GAAG,QAAQ,GAAG,eAAe,CAAC;AAEzF,kDAAkD;AAClD,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,OAAO,EAAE,EAAE,SAAS,SAAO,GAAG,MAAM,CAM1F;AAED,0FAA0F;AAC1F,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAMnE;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAYxE"}
1
+ {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/utils/text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAExH,KAAK,OAAO,GAAG,WAAW,GAAG,YAAY,GAAG,eAAe,GAAG,QAAQ,GAAG,eAAe,CAAC;AAEzF,kDAAkD;AAClD,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,OAAO,EAAE,EAAE,SAAS,SAAO,GAAG,MAAM,CAM1F;AAED,0FAA0F;AAC1F,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAMnE;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAYxE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAc,GAAG,MAAM,CAEjF"}
@@ -33,4 +33,13 @@ export function renderSystemMessageUpdate(message) {
33
33
  }
34
34
  return parts.join("\n\n");
35
35
  }
36
+ /**
37
+ * `text.slice(start, end)` as a string of its own. V8 represents a slice of 13 or more characters as a view that keeps
38
+ * all of `text` alive, so a short excerpt kept from a large text (a 500-character error message cut from a megabyte
39
+ * response body) would keep the whole text alive as long as the excerpt lives. Appending a character and slicing it off
40
+ * again makes V8 copy just the slice.
41
+ */
42
+ export function ownedSlice(text, start, end = text.length) {
43
+ return `${text.slice(start, end)} `.slice(0, -1);
44
+ }
36
45
  //# sourceMappingURL=text.js.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CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,CAAC;QACpE,KAAK,CAAC,IAAI,CACT,KAAK,KAAK,IAAI;YACb,CAAC,CAAC,kCAAkC,IAAI,IAAI;YAC5C,CAAC,CAAC,kCAAkC,IAAI,SAAS,KAAK,EAAE,CACzD,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import type { FallbackContent, ImageContent, SystemMessage, TextContent, ThinkingContent, ToolCall } from \"../types.ts\";\n\ntype Content = TextContent | ImageContent | ThinkingContent | ToolCall | FallbackContent;\n\n/** Extract and join text from message content. */\nexport function contentText(content: string | readonly Content[], separator = \"\\n\"): string {\n\tif (typeof content === \"string\") return content;\n\treturn content\n\t\t.filter((block) => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.join(separator);\n}\n\n/** Render a system message as a complete prompt: its content followed by its sections. */\nexport function getSystemMessageText(message: SystemMessage): string {\n\tconst parts = [contentText(message.content)];\n\tfor (const text of Object.values(message.sections ?? {})) {\n\t\tif (text !== null) parts.push(text);\n\t}\n\treturn parts.filter((part) => part.length > 0).join(\"\\n\\n\");\n}\n\n/**\n * Render a later system message for APIs that accept system messages mid-conversation.\n * Section changes are framed by name so the model can relate them to the leading prompt.\n * This framing is request-time only and may change between versions.\n */\nexport function renderSystemMessageUpdate(message: SystemMessage): string {\n\tconst parts: string[] = [];\n\tconst text = contentText(message.content);\n\tif (text.length > 0) parts.push(text);\n\tfor (const [name, value] of Object.entries(message.sections ?? {})) {\n\t\tparts.push(\n\t\t\tvalue === null\n\t\t\t\t? `Removed system prompt section \"${name}\".`\n\t\t\t\t: `Updated system prompt section \"${name}\":\\n\\n${value}`,\n\t\t);\n\t}\n\treturn parts.join(\"\\n\\n\");\n}\n"]}
1
+ {"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/utils/text.ts"],"names":[],"mappings":"AAIA,kDAAkD;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KAAK,KAAK,IAAI;YACb,CAAC,CAAC,kCAAkC,IAAI,IAAI;YAC5C,CAAC,CAAC,kCAAkC,IAAI,SAAS,KAAK,EAAE,CACzD,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,KAAa,EAAE,GAAG,GAAG,IAAI,CAAC,MAAM;IACxE,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import type { FallbackContent, ImageContent, SystemMessage, TextContent, ThinkingContent, ToolCall } from \"../types.ts\";\n\ntype Content = TextContent | ImageContent | ThinkingContent | ToolCall | FallbackContent;\n\n/** Extract and join text from message content. */\nexport function contentText(content: string | readonly Content[], separator = \"\\n\"): string {\n\tif (typeof content === \"string\") return content;\n\treturn content\n\t\t.filter((block) => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.join(separator);\n}\n\n/** Render a system message as a complete prompt: its content followed by its sections. */\nexport function getSystemMessageText(message: SystemMessage): string {\n\tconst parts = [contentText(message.content)];\n\tfor (const text of Object.values(message.sections ?? {})) {\n\t\tif (text !== null) parts.push(text);\n\t}\n\treturn parts.filter((part) => part.length > 0).join(\"\\n\\n\");\n}\n\n/**\n * Render a later system message for APIs that accept system messages mid-conversation.\n * Section changes are framed by name so the model can relate them to the leading prompt.\n * This framing is request-time only and may change between versions.\n */\nexport function renderSystemMessageUpdate(message: SystemMessage): string {\n\tconst parts: string[] = [];\n\tconst text = contentText(message.content);\n\tif (text.length > 0) parts.push(text);\n\tfor (const [name, value] of Object.entries(message.sections ?? {})) {\n\t\tparts.push(\n\t\t\tvalue === null\n\t\t\t\t? `Removed system prompt section \"${name}\".`\n\t\t\t\t: `Updated system prompt section \"${name}\":\\n\\n${value}`,\n\t\t);\n\t}\n\treturn parts.join(\"\\n\\n\");\n}\n\n/**\n * `text.slice(start, end)` as a string of its own. V8 represents a slice of 13 or more characters as a view that keeps\n * all of `text` alive, so a short excerpt kept from a large text (a 500-character error message cut from a megabyte\n * response body) would keep the whole text alive as long as the excerpt lives. Appending a character and slicing it off\n * again makes V8 copy just the slice.\n */\nexport function ownedSlice(text: string, start: number, end = text.length): string {\n\treturn `${text.slice(start, end)} `.slice(0, -1);\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const PI_AI_VERSION = "0.9.43";
1
+ export declare const PI_AI_VERSION = "0.9.44-alpha.2";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa,WAAW,CAAC"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa,mBAAmB,CAAC"}
@@ -1,3 +1,3 @@
1
1
  // The @bastani/pi-ai package version. scripts/bump-version.ts keeps it in sync with package.json.
2
- export const PI_AI_VERSION = "0.9.43";
2
+ export const PI_AI_VERSION = "0.9.44-alpha.2";
3
3
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CAAC","sourcesContent":["// The @bastani/pi-ai package version. scripts/bump-version.ts keeps it in sync with package.json.\nexport const PI_AI_VERSION = \"0.9.43\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAAC","sourcesContent":["// The @bastani/pi-ai package version. scripts/bump-version.ts keeps it in sync with package.json.\nexport const PI_AI_VERSION = \"0.9.44-alpha.2\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bastani/pi-ai",
3
- "version": "0.9.43",
3
+ "version": "0.9.44-alpha.2",
4
4
  "description": "Bastani-branded unified LLM API with automatic model discovery and provider configuration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",