@animastor/assistant 0.3.1 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.2 (2026-11-22, unpublished)
4
+
5
+ - `edit_book` arguments: the patch list is read through `editBookPatches` —
6
+ accepts `patches` double-encoded as a JSON string (the shape the prod system
7
+ model sent on 22.11: `{"patches": "<json array>"}`; 0.3.1 refused it as
8
+ "called without patches"), a single operation, a bare array, or a nested
9
+ `{patches: {patches: [...]}}`. Broken JSON is still reported as invalid
10
+ arguments.
11
+
3
12
  ## 0.3.1 (2026-11-22, unpublished)
4
13
 
5
14
  Honest edit turns (animastor-docs `CHANGELOG.md` 2026-11-22;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@animastor/assistant",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Animastor Assistant — the AI assistant contour of the Animastor backend, physically extracted from the host: chat engine (persona/system prompts, book context, mode tools, JSON patch pipeline with bundle-contract validation), the /api/v1/ai/* HTTP contour (sessions CRUD, non-streaming chat, SSE streaming with meta/delta/done/error frames, tool-call orchestration) and the chat-session repository contract. The package reaches the host (book read/write, bundle validation, provider resolution, session persistence, shared-inference transport, logging) ONLY through the injected AssistantPorts seam — no PG, no Book internals, no filesystem, no provider gateway inside.",
5
5
  "keywords": [
6
6
  "animastor",
@@ -1082,9 +1082,7 @@ module.exports = function(app, redis, deps) {
1082
1082
  err = 'the book could not be loaded';
1083
1083
  } else {
1084
1084
  try {
1085
- const rawArgs = tc.function.arguments;
1086
- const args = typeof rawArgs === 'string' ? JSON.parse(rawArgs || '{}') : (rawArgs || {});
1087
- const list = Array.isArray(args.patches) ? args.patches : [];
1085
+ const list = chatEngine.editBookPatches(tc.function.arguments);
1088
1086
  if (list.length === 0) {
1089
1087
  err = 'edit_book was called without patches';
1090
1088
  } else {
@@ -762,6 +762,36 @@ module.exports = function(config, deps = {}) {
762
762
  + 'Call `edit_book` now with the JSON Patch operations that implement the change you described. '
763
763
  + 'If you cannot express it as patches, say plainly that the book was not changed.';
764
764
 
765
+ // ── edit_book arguments → patch list (0.3.2) ───────
766
+ // On the prod system model (nemotron, 22.11) edit_book arrived as
767
+ // {"patches": "<JSON text of the array>"} — the array double-encoded as
768
+ // a string; 0.3.1 refused it ("called without patches") and nothing was
769
+ // saved. Accepted shapes (arguments may itself be a JSON string):
770
+ // {patches: [...]} | {patches: "<json array | json object>"} |
771
+ // {patches: {op,path,…}} | {patches: {patches: [...]}} | [...] |
772
+ // {op, path, …} (one operation).
773
+ // Throws on unparseable JSON (the caller reports it); [] = no patches.
774
+ function editBookPatches(rawArgs) {
775
+ const decode = (v) => {
776
+ let x = v;
777
+ for (let i = 0; i < 3 && typeof x === 'string'; i++) {
778
+ const t = x.trim();
779
+ x = t === '' ? null : JSON.parse(t);
780
+ }
781
+ return x;
782
+ };
783
+ const isOp = (x) => !!x && typeof x === 'object' && !Array.isArray(x) && typeof x.op === 'string' && typeof x.path === 'string';
784
+ const args = decode(rawArgs);
785
+ if (Array.isArray(args)) return args;
786
+ if (!args || typeof args !== 'object') return [];
787
+ if (isOp(args)) return [args];
788
+ let p = decode(args.patches);
789
+ if (p && typeof p === 'object' && !Array.isArray(p) && p.patches !== undefined) p = decode(p.patches);
790
+ if (Array.isArray(p)) return p;
791
+ if (isOp(p)) return [p];
792
+ return [];
793
+ }
794
+
765
795
  function applyPatchesValidated(obj, patches) {
766
796
  const { result, errors } = applyPatches(obj, patches);
767
797
  if (errors.length > 0) {
@@ -799,6 +829,7 @@ module.exports = function(config, deps = {}) {
799
829
  normalizeHeroPatches,
800
830
  normalizeBookParticipants,
801
831
  assignMissingIds,
832
+ editBookPatches,
802
833
  looksLikeChangeClaim,
803
834
  EDIT_RETRY_PROMPT,
804
835
  chatRequestExtras,