Tool catalog: file, playback, and clipboard

Run these cells in order in a disposable JupyterLab project. The setup asks for the absolute Jupyter server root and checks that it exists and contains this kernel’s working folder before making server-root-relative file references. Enter the folder JupyterLab serves, even when this notebook and its kernel are in a nested folder. Use a live kernel.

Tool catalog: file, playback, and clipboard

Run these cells in order in a disposable JupyterLab project. The setup asks for the absolute Jupyter server root and checks that it exists and contains this kernel’s working folder before making server-root-relative file references. Enter the folder JupyterLab serves, even when this notebook and its kernel are in a nested folder. Use a live kernel.

The blue PNG and quiet 60-second WAV are generated inputs. The longer clip gives you time to try the playback controls.

Click the file picker, Play, Copy, or paste control when it appears; no browser can perform those user actions silently. Each call returns an immediate receipt, so inspect it on a later turn after the media row completes. The AI questions ask the selected ChatGPT connection to make real, scoped tool calls. Do not run all cells at once.

The saved AI answers below show real browser tool calls and later receipts. Their operation and preview IDs belong to those recorded runs; run the fixture setup to create fresh references in your own session.

Disposable exact media references

from pathlib import Path, PurePosixPath
from uuid import uuid4
import hashlib, math, struct, wave
from PIL import Image
from nbinlineai.tools import (choose_file, open_media, play_media, pause_media, seek_media, set_media_volume, close_media, copy_text, paste_content, operation_status, release_media)
from IPython.display import display, Audio

root_text = input('Absolute Jupyter server root (the folder served by JupyterLab): ').strip()
root_choice = Path(root_text).expanduser()
if not root_choice.is_absolute():
    raise ValueError('Enter an absolute Jupyter server-root folder; do not use the kernel working directory as a guess.')
server_root = root_choice.resolve(strict=True)
if not server_root.is_dir() or not Path.cwd().resolve().is_relative_to(server_root):
    raise ValueError('The server root must be an existing folder containing this kernel working directory.')

def server_ref(path):
    """Make a server-root-relative path for an owned file or save destination."""
    target = Path(path).resolve()
    return target.relative_to(server_root).as_posix()

def server_file(reference):
    """Map a server-returned relative path to the configured local root."""
    if not isinstance(reference, str) or not reference or '\\' in reference:
        raise ValueError('Expected a server-root-relative media path.')
    relative = PurePosixPath(reference)
    if relative.is_absolute() or relative.as_posix() != reference or reference == '.' or '..' in relative.parts:
        raise ValueError('Media path must be a clean server-root-relative path.')
    candidate = server_root / reference
    if not candidate.resolve().is_relative_to(server_root):
        raise ValueError('Media path escapes the configured server root.')
    return candidate
nonce = uuid4().hex
image_path = Path.cwd() / f'playback-{nonce}.png'
tone_path = Path.cwd() / f'playback-{nonce}.wav'
Image.new('RGB', (2, 2), (36, 112, 195)).save(image_path)
with wave.open(str(tone_path), 'wb') as output:
    output.setnchannels(1); output.setsampwidth(2); output.setframerate(16000)
    output.writeframes(b''.join(struct.pack('<h', int(1200 * math.sin(2 * math.pi * 440 * i / 16000))) for i in range(60 * 16000)))
image_ref = {'path': server_ref(image_path), 'sha256': hashlib.sha256(image_path.read_bytes()).hexdigest()}
tone_ref = {'path': server_ref(tone_path), 'sha256': hashlib.sha256(tone_path.read_bytes()).hexdigest()}
print('Generated quiet 60-second 440 Hz WAV:', tone_path.name)
print('Generated blue PNG:', image_path.name)
display(Image.open(image_path).resize((80, 80)))
display(Audio(filename=str(tone_path), normalize=False))
Generated quiet 60-second 440 Hz WAV: playback-ca4f55ff9e5749259451859ed64d7244.wav
Generated blue PNG: playback-ca4f55ff9e5749259451859ed64d7244.png

choose_file

from nbinlineai.tools import choose_file
selected = choose_file(accept='image/png')
selected  # In the visible chooser select only the generated playback-*.png sample.
BrowserReceipt(operation_id=None, status='running')
print('Chosen file:', selected.status, selected.error)
if selected.status == 'completed':
    print('Imported image:', {key: selected.media.get(key) for key in ('media_id', 'mime_type', 'sha256')})
    display(selected.result.resize((80, 80)))
Chosen file: completed None
Imported image: {'media_id': 'WHINiJM-gHDtDYi0yqTCqJ9P9vP_nzF5', 'mime_type': 'image/png', 'sha256': '15718af7fc5d8f1378cbbaf994dbb1a135c5e28ed8ff9550efacd6f3d89cd251'}

Use &choose_file with accept='image/png' so I can select this notebook’s generated blue PNG in the visible picker. Report the immediate operation ID/state only; do not choose a personal file or claim a hash before selection completes.

Operation ID: 8EHbkb4pBCcmmEkEpKCHGS2Gzg72Gfm_; state: waiting_for_user.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
choose_file accept=‘image/png’ receipt accepted Operation ID: 8EHbkb4pBCcmmEkEpKCHGS2Gzg72Gfm_; state: waiting_for_user.

After I select the generated PNG, use &operation_status on the choose_file operation ID. Report actual MIME type, SHA-256, and managed media ID only if completed; otherwise retry later.

Completed. MIME type: image/png; SHA-256: 15718af7fc5d8f1378cbbaf994dbb1a135c5e28ed8ff9550efacd6f3d89cd251; managed media ID: eFXuClHYeeCAfxqUKeRbOp5uW7lAI-HK.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
operation_status exact previous operation ID completed Completed. MIME type: image/png; SHA-256: 15718af7fc5d8f1378cbbaf994dbb1a135c5e28ed8ff9550efacd6f3d89cd251; managed media ID: eFXuClHYeeCAfxqUKeRbOp5uW7lAI-HK.

Use &release_media only on the managed media ID from the completed AI file-choice status. Report the immediate release operation ID/state; the displayed Python image remains available.

Release operation ID: hCRVo0-eeoosKzeIApQsEJdw_icJclZo; result: released: true. The displayed Python image remains available.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
release_media owned imported image ID completed Release operation ID: hCRVo0-eeoosKzeIApQsEJdw_icJclZo; result: released: true. The displayed Python image remains available.

open_media

from nbinlineai.tools import open_media
opened = open_media(tone_ref)
opened  # The owned preview uses the exact WAV bytes and hash.
BrowserReceipt(operation_id=None, status='running')
print('Open preview:', opened.status, opened.error)
if opened.status == 'completed':
    preview_id = opened.result['preview_id']
    print('Preview ID:', preview_id)
Open preview: completed None
Preview ID: f4580ddc708d7c6804c1d03990d961b8

Use &open_media with the exact quiet 60-second WAV reference $tone_ref. Report its immediate operation ID/state; do not claim a preview ID until the later status question confirms it.

Operation ID: FYJabGyMpHKhX5hAjPulUFejI4gq5yKu; state: running.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
open_media exact generated WAV reference receipt accepted Operation ID: FYJabGyMpHKhX5hAjPulUFejI4gq5yKu; state: running.

Use &operation_status on the AI open_media operation ID after completion. Report its actual preview ID and media type; if still running, stop and retry later.

Completed. Preview ID: 44ef42ce41fe6b14e9b5604875f41f64; media type: audio.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
operation_status exact previous operation ID completed Completed. Preview ID: 44ef42ce41fe6b14e9b5604875f41f64; media type: audio.

Use &close_media only on the new preview ID from the preceding completed AI open status. Report the close operation ID/state; leave the direct Python preview open for later controls.

Close operation ID: TWwFSCAgAt46VSDSQ85JgoquXAKuWtza; state: running. The direct Python preview was not targeted.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
close_media extra AI preview ID receipt accepted Close operation ID: TWwFSCAgAt46VSDSQ85JgoquXAKuWtza; state: running. The direct Python preview was not targeted.

Use &operation_status on that AI close_media operation ID after completion. Confirm only the extra AI preview closed.

The close operation completed (closed: true). Only the extra AI preview was targeted; the direct Python preview was not.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
operation_status exact previous operation ID completed The close operation completed (closed: true). Only the extra AI preview was targeted; the direct Python preview was not.

play_media

from nbinlineai.tools import play_media
assert opened.status == 'completed', 'Wait for the preview, then rerun this cell.'
playing = play_media(opened.result['preview_id'])
playing  # Click Play in the visible panel if the browser requires activation.
BrowserReceipt(operation_id=None, status='running')
print('Play:', playing.status, playing.result, playing.error)
Play: completed {'playing': True, 'seconds': 0} None

Use &play_media on the direct preview ID $preview_id. Report its immediate operation ID/state. I will click the visible Play control if the browser waits for activation.

Operation ID: kA9hy4CPboxoQQ6Rz2axfW-W_0ens9zx; state: waiting_for_user. Click the visible Play control to activate playback.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
play_media owned preview ID receipt accepted Operation ID: kA9hy4CPboxoQQ6Rz2axfW-W_0ens9zx; state: waiting_for_user. Click the visible Play control to activate playback.

After any visible Play click, use &operation_status on that play_media operation ID. Report actual playback state only if completed; otherwise retry later.

Completed: playback is active (playing: true, at 0.11235 seconds).

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
operation_status exact previous operation ID completed Completed: playback is active (playing: true, at 0.11235 seconds).

pause_media

from nbinlineai.tools import pause_media
paused = pause_media(opened.result['preview_id'])
paused
BrowserReceipt(operation_id=None, status='running')
print('Pause:', paused.status, paused.result, paused.error)
Pause: completed {'playing': False, 'seconds': 5.107447} None

Use &pause_media on preview ID $preview_id. Report its immediate operation ID/state, not a final paused state.

Operation ID: vWyII4C5xfmVOZm2PZbelzZOKqmjtfek; state: running.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
pause_media owned preview ID receipt accepted Operation ID: vWyII4C5xfmVOZm2PZbelzZOKqmjtfek; state: running.

Use &operation_status on that pause_media operation ID after completion. Report the actual paused state.

Pause completed: playback is paused (playing: false) at 41.751484 seconds.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
operation_status exact previous operation ID completed Pause completed: playback is paused (playing: false) at 41.751484 seconds.

seek_media

from nbinlineai.tools import seek_media
seeked = seek_media(opened.result['preview_id'], 2.5)
seeked
BrowserReceipt(operation_id=None, status='running')
print('Seek:', seeked.status, seeked.result, seeked.error)
Seek: completed {'seconds': 2.5} None

Use &seek_media on preview ID $preview_id at 2.5 seconds of the generated 60-second tone. Report its immediate operation ID/state, not the final actual position.

Operation ID: LeDsBUZ_b8eS6oX_8JzRhVg6WVCS-ro8; state: running.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
seek_media owned preview ID, 2.5 seconds receipt accepted Operation ID: LeDsBUZ_b8eS6oX_8JzRhVg6WVCS-ro8; state: running.

Use &operation_status on that seek_media operation ID after completion. Report actual position, which can differ slightly from the requested 2.5 seconds.

Seek completed. Actual position: 2.5 seconds.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
operation_status exact previous operation ID completed Seek completed. Actual position: 2.5 seconds.

set_media_volume

from nbinlineai.tools import set_media_volume
volume = set_media_volume(opened.result['preview_id'], 0.25)
volume
BrowserReceipt(operation_id=None, status='running')
print('Volume:', volume.status, volume.result, volume.error)
Volume: completed {'level': 0.25} None

Use &set_media_volume on preview ID $preview_id with volume 0.25. Report its immediate operation ID/state; the browser may restrict volume changes.

Operation ID: iktqjsjmy0oHU7Xq_z33VGPnq3log_d_; state: running.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
set_media_volume owned preview ID, level 0.25 receipt accepted Operation ID: iktqjsjmy0oHU7Xq_z33VGPnq3log_d_; state: running.

Use &operation_status on that set_media_volume operation ID. Report the actual result or browser restriction without claiming the volume changed if it did not.

Completed: the volume was set to 0.25.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
operation_status exact previous operation ID completed Completed: the volume was set to 0.25.

close_media

The earlier AI close question closes only the extra preview created by AI Open. The Python call below closes its separate preview.

from nbinlineai.tools import close_media
closed = close_media(opened.result['preview_id'])
selected_release = release_media(selected.media['media_id']) if selected.status == 'completed' and selected.media.get('media_id') else None
closed
BrowserReceipt(operation_id=None, status='running')
print('Close preview:', closed.status, closed.result, closed.error)
print('Release selected PNG:', selected_release.status, selected_release.error) if selected_release else print('No managed PNG to release.')
print('Original 60-second WAV remains:', tone_path.exists())
Close preview: completed {'closed': True} None
Release selected PNG: completed None
Original 60-second WAV remains: True

copy_text

from nbinlineai.tools import copy_text
copied = copy_text('nbinlineai disposable playback sample')
copied  # Click the visible Copy button or use the browser copy shortcut.
BrowserReceipt(operation_id=None, status='running')
print('Copy:', copied.status, copied.result, copied.error)
Copy: completed {'copied': True, 'method': 'manual'} None

Use &copy_text with the literal nbinlineai disposable playback sample. Report its immediate operation ID/state. Ask me to click the visible Copy control if the browser waits.

Operation ID: 9EIDD_ulazz6flH9o9POip7h3wgXEpgC; state: waiting_for_user. Please click the visible Copy control.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
copy_text ‘nbinlineai disposable playback sample’ receipt accepted Operation ID: 9EIDD_ulazz6flH9o9POip7h3wgXEpgC; state: waiting_for_user. Please click the visible Copy control.

After I click Copy, use &operation_status on that copy_text operation ID. Report the actual terminal state; do not claim success from an initial waiting snapshot.

Completed: text copied via the browser (copied: true).

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
operation_status exact previous operation ID completed Completed: text copied via the browser (copied: true).

paste_content

In the saved AI Paste run, the operator seeded the CUA test clipboard with the exact disposable sample, then pasted into the visible browser field. The preceding Copy result was verified separately; the Paste example does not claim those bytes were transferred from Copy.

from nbinlineai.tools import paste_content
pasted = paste_content(accept='text')
pasted  # Click the visible paste box and paste the sample text.
BrowserReceipt(operation_id=None, status='running')
print('Paste:', pasted.status, pasted.error)
if pasted.status == 'completed':
    print('Pasted text:', pasted.result)
Paste: completed None
Pasted text: {'text': 'nbinlineai disposable playback sample', 'truncated': False, 'original_chars': 37}

Use &paste_content with accept='text'. Report its immediate operation ID/state. Ask me to paste the disposable sample into the visible paste box; do not read the clipboard silently.

Operation ID: 7j7_4gFEIJDXZeIbz3svsFIx2A5h7UYS; state: waiting_for_user. Please paste the disposable sample into the visible paste box.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
paste_content accept=‘text’ receipt accepted Operation ID: 7j7_4gFEIJDXZeIbz3svsFIx2A5h7UYS; state: waiting_for_user. Please paste the disposable sample into the visible paste box.

After I paste the disposable text, use &operation_status on that paste_content operation ID. Quote only its actual bounded returned text and truncation flag if completed; otherwise retry later.

Completed. Returned text: nbinlineai disposable playback sample; truncated: false.

Observed live tool call for the answer above (isolated JupyterLab and ChatGPT subscription).

Tool Submitted arguments Result state Observed answer
operation_status exact previous operation ID completed Completed. Returned text: nbinlineai disposable playback sample; truncated: false.
for generated in (tone_path, image_path):
    generated.unlink(missing_ok=True)
print('Disposable playback samples removed:', not tone_path.exists() and not image_path.exists())
if globals().get('selected_release'):
    print('Imported image release:', selected_release.status, selected_release.error)
Disposable playback samples removed: True
Imported image release: completed None

← Examples guide · Download this notebook