codebind 0.6.17__py3-none-any.whl → 0.6.18__py3-none-any.whl

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.
codebind/conversation.py CHANGED
@@ -19,6 +19,7 @@ from langchain_core.messages import (
19
19
  )
20
20
 
21
21
  from .images import PreparedImage, prepare_mime_image
22
+ from .model_text import bounded_text
22
23
 
23
24
 
24
25
  class ConversationStore(Protocol):
@@ -319,7 +320,19 @@ def _canonical_mime_bundle(
319
320
  label: str,
320
321
  images: list[tuple[str, PreparedImage]] | None,
321
322
  ) -> dict[str, Any]:
322
- data = {key: deepcopy(item) for key, item in value.items() if not key.startswith("image/")}
323
+ def bounded_item(key: str, item: Any) -> Any:
324
+ if key.startswith("text/"):
325
+ if isinstance(item, str):
326
+ return bounded_text(item)
327
+ if isinstance(item, list) and all(isinstance(part, str) for part in item):
328
+ return bounded_text("".join(item))
329
+ return deepcopy(item)
330
+
331
+ data = {
332
+ key: bounded_item(key, item)
333
+ for key, item in value.items()
334
+ if not key.startswith("image/")
335
+ }
323
336
  try:
324
337
  image = prepare_mime_image(value)
325
338
  except ValueError as error:
@@ -370,7 +383,7 @@ def _normalize_notebook(
370
383
  ):
371
384
  raise ValueError("Invalid Codebind notebook cell")
372
385
  identifiers.add(identifier)
373
- cell: dict[str, Any] = {"id": identifier, "type": cell_type, "source": source}
386
+ cell: dict[str, Any] = {"id": identifier, "type": cell_type, "source": bounded_text(source)}
374
387
  if cell_type == "code":
375
388
  execution_count = raw_cell.get("execution_count")
376
389
  outputs = raw_cell.get("outputs", [])
@@ -384,6 +397,12 @@ def _normalize_notebook(
384
397
  if not isinstance(output, dict):
385
398
  raise ValueError("Invalid Codebind cell output")
386
399
  normalized = deepcopy(output)
400
+ if output.get("output_type") == "stream":
401
+ text = output.get("text")
402
+ if isinstance(text, str):
403
+ normalized["text"] = bounded_text(text)
404
+ elif isinstance(text, list) and all(isinstance(part, str) for part in text):
405
+ normalized["text"] = bounded_text("".join(text))
387
406
  data = output.get("data")
388
407
  if isinstance(data, dict):
389
408
  normalized["data"] = _canonical_mime_bundle(
codebind/execution.py CHANGED
@@ -16,6 +16,7 @@ from IPython.utils.capture import capture_output
16
16
 
17
17
  from .display import display_cell
18
18
  from .images import PreparedImage, prepare_mime_image
19
+ from .model_text import bounded_text
19
20
  from .jupyter import JupyterLabBridge
20
21
  from .terminal import preview_tool_output, record_tool_output, show_input
21
22
 
@@ -388,9 +389,10 @@ class IPythonExecutor:
388
389
  displays: list[str] = []
389
390
  images: list[PreparedImage] = []
390
391
  omissions: list[str] = []
392
+ seen_images: set[str] = set()
391
393
  for index, data in enumerate(bundles):
392
394
  if isinstance(data, dict) and "text/plain" in data:
393
- displays.append(str(data["text/plain"]))
395
+ displays.append(bounded_text(str(data["text/plain"])))
394
396
  if not isinstance(data, dict):
395
397
  continue
396
398
  if len(images) >= _MAXIMUM_IMAGES_PER_REPORT:
@@ -402,20 +404,27 @@ class IPythonExecutor:
402
404
  except ValueError as error:
403
405
  omissions.append(f"Display {index + 1}: {error}")
404
406
  else:
405
- if image is not None:
407
+ if image is not None and image.source_sha256 not in seen_images:
406
408
  images.append(image)
409
+ seen_images.add(image.source_sha256)
407
410
 
408
411
  exception = result.error_before_exec or result.error_in_exec
409
412
  error = (
410
- {"type": type(exception).__name__, "message": str(exception)}
413
+ {"type": type(exception).__name__, "message": bounded_text(str(exception))}
411
414
  if exception is not None
412
415
  else None
413
416
  )
417
+ value = result.result
418
+ rendered_result = (
419
+ f"<{type(value).__name__}: {len(value):,} bytes>"
420
+ if isinstance(value, (bytes, bytearray, memoryview))
421
+ else bounded_text(repr(value)) if value is not None else None
422
+ )
414
423
  return ExecutionReport(
415
424
  ok=result.success,
416
- stdout=stdout,
417
- stderr=stderr,
418
- result=repr(result.result) if result.result is not None else None,
425
+ stdout=bounded_text(stdout),
426
+ stderr=bounded_text(stderr),
427
+ result=rendered_result,
419
428
  displays=tuple(displays),
420
429
  error=error,
421
430
  images=tuple(images),
codebind/model_text.py ADDED
@@ -0,0 +1,16 @@
1
+ """Keep model-facing text bounded without changing native IPython history."""
2
+
3
+ from __future__ import annotations
4
+
5
+ MAXIMUM_MODEL_TEXT_CHARACTERS = 16_384
6
+
7
+
8
+ def bounded_text(value: str, limit: int = MAXIMUM_MODEL_TEXT_CHARACTERS) -> str:
9
+ """Keep useful head and tail text; do not send enormous binary representations."""
10
+ if len(value) <= limit:
11
+ return value
12
+ if value.startswith(("b'", 'b"', "bytearray(b'", 'bytearray(b"')):
13
+ return f"<binary representation omitted: {len(value):,} characters>"
14
+ head, tail = limit // 2, limit // 4
15
+ omitted = len(value) - head - tail
16
+ return value[:head] + f"\n… {omitted:,} characters omitted …\n" + value[-tail:]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codebind
3
- Version: 0.6.17
3
+ Version: 0.6.18
4
4
  Summary: A frontend-neutral model loop for persistent IPython sessions.
5
5
  Keywords: ai,ipython,llm,repl,agents
6
6
  Author: Giovanni Gravili
@@ -80,7 +80,7 @@ Inspect this project and tell me what to implement first.
80
80
  Codebind keeps its terminal prompt and internal bookkeeping usable when a tool cell leaves an asyncio loop active on the terminal thread. This also supports sync clients that manage their own loop across tool cells, without changing IPython’s normal top-level `await` behavior.
81
81
 
82
82
  Terminal conversations remain live for the current IPython process. Previous terminal inputs and outputs, including Python cells you ran yourself, enter the model's context when you ask a question. Durable automatic resumption belongs to notebooks, where the notebook file provides an unambiguous conversation identity.
83
- Model-executed cells appear with IPython's native input counter, syntax highlighting, output prompts, streams, and tracebacks. Assistant Markdown appears before the following tool cell, and tool output appears as it is written. To keep terminal scrollback usable, Codebind previews at most three gray output lines, shortening each line after 80 characters with `...`. Further lines appear as `… N more output lines.` The complete output remains available to the model and in IPython history; `%output 8` opens the full text of cell 8 in IPython's pager. User-entered Python cells keep IPython's normal display behavior. Assistant Markdown is rendered through IPython's terminal MIME renderer. A terminal is a stream rather than a notebook document, so these displays are not editable notebook cells.
83
+ Model-executed cells appear with IPython's native input counter, syntax highlighting, output prompts, streams, and tracebacks. Assistant Markdown appears before the following tool cell, and tool output appears as it is written. To keep terminal scrollback usable, Codebind previews at most three gray output lines, shortening each line after 80 characters with `...`. Further lines appear as `… N more output lines.` Full output remains in IPython history, while model-facing text is bounded and displayed images stay available as image blocks; `%output 8` opens the full text of cell 8 in IPython's pager. User-entered Python cells keep IPython's normal display behavior. Assistant Markdown is rendered through IPython's terminal MIME renderer. A terminal is a stream rather than a notebook document, so these displays are not editable notebook cells.
84
84
 
85
85
  ## JupyterLab
86
86
 
@@ -4,24 +4,25 @@ codebind/cli.py,sha256=9LOR1L3P8sPsOOgsnpbOsA1PNUZdAj1Z9ROFKeo3EV8,423
4
4
  codebind/configuration.py,sha256=b9ux-MiepzAFfRhorZp4w2pdLLs44necescIGg_IKfo,1828
5
5
  codebind/context.md,sha256=Iht9nJx7drsvjXYiTm-vG-prXx1UQU4VdMgBecWubJI,64
6
6
  codebind/context.py,sha256=Lo7WmsOrS1RE3Vk_Lo0Pig8IFK_-RVQOuRPVagvOziM,6051
7
- codebind/conversation.py,sha256=nFMe2QgFkFOA2GYInN-cO_jhA9010LpM6_Ij2g4Q2BA,17500
7
+ codebind/conversation.py,sha256=q7KXXilacg7-BBXOU80-ErRQNf0S6_DQ8YEZYWpYWcs,18309
8
8
  codebind/display.py,sha256=IpxcElyNcr5olRIatEduN_d-sRwpsMlaq1UtrOXocQA,494
9
- codebind/execution.py,sha256=RBZ6RLs_iFiXBTA2VtWFuIuFN9Auf924vNeH58u1P-I,17324
9
+ codebind/execution.py,sha256=EdxggTM1wGzvKMCtFM4pFNFMlsZJpMjS2u-AbmBUL9U,17781
10
10
  codebind/extension.py,sha256=JHHSfeWsxRzpsoLeFDmaWEiiQNudZKoXo53y_AOxIjg,11436
11
11
  codebind/images.py,sha256=9bJHjXc75_YRBFTAqAWiknRTCjs8ApyGVVSxC_S5lio,4342
12
12
  codebind/instructions.md,sha256=gmj5xtqVxzHPpj32XaxdvoaDwSOchqhH3Ca4aHFLqnw,4745
13
13
  codebind/jupyter.py,sha256=Chl14OBGA_EN99bEiO0rHEQJ6vLdCw-PhaC2JWwpOQ4,9551
14
+ codebind/model_text.py,sha256=vBWLfQG7oo66DW5f5Y-VTMzB9KJnjCXs-NP6uRgX7WM,688
14
15
  codebind/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
16
  codebind/session.py,sha256=Ty3fkVxSDVndE7rrH_uoTaK26NI-Aj0CiK8XjyxaZXY,24377
16
17
  codebind/terminal.py,sha256=JGguwP1IGC_EsH02DM8Ifrz832U07Tdz8DkFtbPCVwc,19294
17
- codebind-0.6.17.dist-info/licenses/LICENSE,sha256=ujX46e0LFBIBTnCDY0u3Q7LV363B7CiI7QJZxIkEXlk,1073
18
- codebind-0.6.17.data/data/share/jupyter/labextensions/codebind-jupyterlab/install.json,sha256=78rEThkfrk1pXtekX5WrG9_Y0lJYi5XBEm8n9athpFE,164
19
- codebind-0.6.17.data/data/share/jupyter/labextensions/codebind-jupyterlab/package.json,sha256=kTlYeh6jdbfq3K3EOza3bcKzhNpPO_-5Uniw-wCyfIo,1193
20
- codebind-0.6.17.data/data/share/jupyter/labextensions/codebind-jupyterlab/static/590.98c719a309e23852.js,sha256=3_28fXeGzVozV517cjkmxSSO9ccdVOe-4-RMBf46p8w,17613
21
- codebind-0.6.17.data/data/share/jupyter/labextensions/codebind-jupyterlab/static/remoteEntry.24258c9500a0850a.js,sha256=eWX4O8-R_o-6pVn1LSxUHs3LC8qfi-xX4Vg1QLwy3gg,11795
22
- codebind-0.6.17.data/data/share/jupyter/labextensions/codebind-jupyterlab/static/style.js,sha256=Opy15wyuR_ABqsrk-cOcOj2yZtvtq0r36aDkErnloD0,113
23
- codebind-0.6.17.data/data/share/jupyter/labextensions/codebind-jupyterlab/static/third-party-licenses.json,sha256=MNToQfru1YnHAie-2Virp23yWsc5co3qG0IzrO6SEfw,20
24
- codebind-0.6.17.dist-info/WHEEL,sha256=e4_1dyBeezi8ZjfxrZ3bnVOxFDa3ksqVqH0jTHkUZ3k,81
25
- codebind-0.6.17.dist-info/entry_points.txt,sha256=GiPcU63sULDlywJSKigAS4M3vaziYIrubXOb3fAg2_c,48
26
- codebind-0.6.17.dist-info/METADATA,sha256=FNcN4HFs5GSpVnNziWkkKBnqAQt2w0z-HheAjGI17CM,8829
27
- codebind-0.6.17.dist-info/RECORD,,
18
+ codebind-0.6.18.dist-info/licenses/LICENSE,sha256=ujX46e0LFBIBTnCDY0u3Q7LV363B7CiI7QJZxIkEXlk,1073
19
+ codebind-0.6.18.data/data/share/jupyter/labextensions/codebind-jupyterlab/install.json,sha256=78rEThkfrk1pXtekX5WrG9_Y0lJYi5XBEm8n9athpFE,164
20
+ codebind-0.6.18.data/data/share/jupyter/labextensions/codebind-jupyterlab/package.json,sha256=kTlYeh6jdbfq3K3EOza3bcKzhNpPO_-5Uniw-wCyfIo,1193
21
+ codebind-0.6.18.data/data/share/jupyter/labextensions/codebind-jupyterlab/static/590.98c719a309e23852.js,sha256=3_28fXeGzVozV517cjkmxSSO9ccdVOe-4-RMBf46p8w,17613
22
+ codebind-0.6.18.data/data/share/jupyter/labextensions/codebind-jupyterlab/static/remoteEntry.24258c9500a0850a.js,sha256=eWX4O8-R_o-6pVn1LSxUHs3LC8qfi-xX4Vg1QLwy3gg,11795
23
+ codebind-0.6.18.data/data/share/jupyter/labextensions/codebind-jupyterlab/static/style.js,sha256=Opy15wyuR_ABqsrk-cOcOj2yZtvtq0r36aDkErnloD0,113
24
+ codebind-0.6.18.data/data/share/jupyter/labextensions/codebind-jupyterlab/static/third-party-licenses.json,sha256=MNToQfru1YnHAie-2Virp23yWsc5co3qG0IzrO6SEfw,20
25
+ codebind-0.6.18.dist-info/WHEEL,sha256=e4_1dyBeezi8ZjfxrZ3bnVOxFDa3ksqVqH0jTHkUZ3k,81
26
+ codebind-0.6.18.dist-info/entry_points.txt,sha256=GiPcU63sULDlywJSKigAS4M3vaziYIrubXOb3fAg2_c,48
27
+ codebind-0.6.18.dist-info/METADATA,sha256=w_o8HwiGSUxcUp-VdyUos4YzIhj9Fr2dBVor9cUUfC4,8882
28
+ codebind-0.6.18.dist-info/RECORD,,