1. Go to this page and download the library: Download particle-academy/last-word library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
particle-academy / last-word example snippets
use LastWord\Agent;
$doc = [
'title' => 'Quarterly Notes',
'blocks' => [
['type' => 'heading', 'level' => 1, 'runs' => [['text' => 'Summary']]],
['type' => 'paragraph', 'runs' => [
['text' => 'Revenue was '],
['text' => 'up 12%', 'bold' => true],
['text' => ' — details in the '],
['text' => 'appendix', 'link' => 'https://example.com/appendix'],
['text' => '.'],
]],
['type' => 'list', 'items' => [
['runs' => [['text' => 'Ship the docx engine']], 'children' => [
['runs' => [['text' => 'Reader + writer']]],
]],
['runs' => [['text' => 'Wire the Editor bridge']]],
]],
],
];
// Validate before writing — catches malformed agent output
$errors = Agent::validate($doc); // [] when valid: [{path, message}, …] otherwise
// Write to disk (synchronous)
$result = Agent::write($doc, storage_path('app/notes.docx'));
// ['path' => …, 'bytes' => 4151, 'blocks' => 3]
// Or keep it in memory
$bytes = Agent::toBytes($doc);
// And read any .docx back into the same model — including Word-authored files
$model = Agent::read($bytes); // or Agent::read('/path/to/file.docx')
use LastWord\Agent;
// Inbound: a Word file arrives → markdown for the Editor
$doc = Agent::read($uploadedBytes);
$markdown = Agent::toMarkdown($doc);
// … the Editor (or an agent) edits the markdown …
// Outbound: markdown → model → a real .docx
$doc = Agent::fromMarkdown($markdown);
$bytes = Agent::toBytes($doc);
$images = [
'logo' => ['data' => file_get_contents('logo.png'), 'widthPx' => 150, 'heightPx' => 50, 'alt' => 'Acme Ltd'],
'seal' => 'data:image/jpeg;base64,...',
];
Agent::guide(['images' => $images]); // the guide, plus a section listing image:logo and image:seal
Agent::jsonSchema(['images' => $images]); // the image src takes exactly those names, or a data URL
Agent::toBytes([
'page' => ['header' => ['blocks' => [['type' => 'image', 'src' => 'image:logo']]]],
'blocks' => $blocks,
], ['images' => $images]);
$cat = Agent::catalog($docx); // headings + tables, each with its selector
$x = Agent::extract($docx, ['underHeading' => 'Results', 'nth' => 0]);
// {ok: true, content: {fancyContent: 1, ...}, report} or {ok: false, refused: {reason}}
$doc['blocks'][] = ['type' => 'portable', 'content' => $sheetRange]; // e.g. from holy-sheet extract()
Agent::toBytes(Agent::validateAndRepair($doc)['schema']);
use LastWord\Exchange\ExportPolicy;
$policy = new ExportPolicy(['allow' => ['markdown', 'html']]);
Agent::export($bytes, 'html', ['selector' => ['table' => 0]], $policy);
// {ok: true, target, mime, text|bytes, report} or {ok: false, refused: {reason, target, message, ...}}
Agent::exportToolDefinition($policy); // the tool an agent sees: only enabled targets