@introspection-ai/recipes 0.54.0 → 0.56.0
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/dist/artifact-links.d.ts +25 -0
- package/dist/artifact-links.d.ts.map +1 -0
- package/dist/artifact-links.js +92 -0
- package/dist/artifact-links.js.map +1 -0
- package/dist/artifact-viewer-tui.d.ts +2 -1
- package/dist/artifact-viewer-tui.d.ts.map +1 -1
- package/dist/artifact-viewer-tui.js.map +1 -1
- package/dist/artifact-viewer.d.ts +2 -1
- package/dist/artifact-viewer.d.ts.map +1 -1
- package/dist/artifact-viewer.js +49 -3
- package/dist/artifact-viewer.js.map +1 -1
- package/dist/artifact.d.ts +5 -4
- package/dist/artifact.d.ts.map +1 -1
- package/dist/artifact.js +4 -1
- package/dist/artifact.js.map +1 -1
- package/dist/batch/files.d.ts +16 -0
- package/dist/batch/files.d.ts.map +1 -0
- package/dist/batch/files.js +58 -0
- package/dist/batch/files.js.map +1 -0
- package/dist/batch/index.d.ts +67 -0
- package/dist/batch/index.d.ts.map +1 -0
- package/dist/batch/index.js +109 -0
- package/dist/batch/index.js.map +1 -0
- package/dist/batch/limiter.d.ts +20 -0
- package/dist/batch/limiter.d.ts.map +1 -0
- package/dist/batch/limiter.js +54 -0
- package/dist/batch/limiter.js.map +1 -0
- package/dist/batch/lines.d.ts +58 -0
- package/dist/batch/lines.d.ts.map +1 -0
- package/dist/batch/lines.js +77 -0
- package/dist/batch/lines.js.map +1 -0
- package/dist/batch/params.d.ts +30 -0
- package/dist/batch/params.d.ts.map +1 -0
- package/dist/batch/params.js +48 -0
- package/dist/batch/params.js.map +1 -0
- package/dist/batch/runner.d.ts +77 -0
- package/dist/batch/runner.d.ts.map +1 -0
- package/dist/batch/runner.js +240 -0
- package/dist/batch/runner.js.map +1 -0
- package/dist/batch/shards.d.ts +42 -0
- package/dist/batch/shards.d.ts.map +1 -0
- package/dist/batch/shards.js +115 -0
- package/dist/batch/shards.js.map +1 -0
- package/dist/connector-tools.d.ts +1 -1
- package/dist/connector-tools.d.ts.map +1 -1
- package/dist/connector-tools.js +15 -0
- package/dist/connector-tools.js.map +1 -1
- package/dist/documents/arguments.d.ts +17 -0
- package/dist/documents/arguments.d.ts.map +1 -1
- package/dist/documents/arguments.generated.d.ts +2 -1
- package/dist/documents/arguments.generated.d.ts.map +1 -1
- package/dist/documents/arguments.generated.js +22 -0
- package/dist/documents/arguments.generated.js.map +1 -1
- package/dist/documents/index.d.ts +1 -1
- package/dist/documents/index.d.ts.map +1 -1
- package/dist/documents/module.d.ts.map +1 -1
- package/dist/documents/module.js +2 -0
- package/dist/documents/module.js.map +1 -1
- package/dist/documents/tools.d.ts +1 -1
- package/dist/documents/tools.d.ts.map +1 -1
- package/dist/documents/tools.js +71 -6
- package/dist/documents/tools.js.map +1 -1
- package/dist/documents/types.d.ts +96 -0
- package/dist/documents/types.d.ts.map +1 -1
- package/dist/interactions.d.ts +6 -0
- package/dist/interactions.d.ts.map +1 -1
- package/dist/interactions.js +9 -0
- package/dist/interactions.js.map +1 -1
- package/dist/mcp-chunks/{chunk-53T5TVPR.js → chunk-AJDK5Z7O.js} +1 -1
- package/dist/mcp-chunks/{chunk-D6OGGMWS.js → chunk-KZGUH7E2.js} +1 -0
- package/dist/mcp-chunks/{server-SLD55EBC.js → server-HQBFWAJR.js} +2 -2
- package/dist/mcp-daemon.js +2 -2
- package/dist/mcp-run-worker.js +1 -1
- package/dist/otel-baggage.d.ts +7 -0
- package/dist/otel-baggage.d.ts.map +1 -0
- package/dist/otel-baggage.js +7 -0
- package/dist/otel-baggage.js.map +1 -0
- package/dist/recipe/manifest.generated.d.ts +3 -1
- package/dist/recipe/manifest.generated.d.ts.map +1 -1
- package/dist/recipe/manifest.generated.js +4 -2
- package/dist/recipe/manifest.generated.js.map +1 -1
- package/dist/recipe/package.d.ts +12 -0
- package/dist/recipe/package.d.ts.map +1 -1
- package/dist/recipe/package.js +32 -0
- package/dist/recipe/package.js.map +1 -1
- package/dist/review.d.ts +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +1 -1
- package/dist/review.js.map +1 -1
- package/dist/session.d.ts +4 -2
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +29 -10
- package/dist/session.js.map +1 -1
- package/dist/signature/arguments.d.ts +78 -0
- package/dist/signature/arguments.d.ts.map +1 -0
- package/dist/signature/arguments.generated.d.ts +9 -0
- package/dist/signature/arguments.generated.d.ts.map +1 -0
- package/dist/signature/arguments.generated.js +129 -0
- package/dist/signature/arguments.generated.js.map +1 -0
- package/dist/signature/arguments.js +8 -0
- package/dist/signature/arguments.js.map +1 -0
- package/dist/signature/docx.d.ts +41 -0
- package/dist/signature/docx.d.ts.map +1 -0
- package/dist/signature/docx.js +449 -0
- package/dist/signature/docx.js.map +1 -0
- package/dist/signature/index.d.ts +9 -0
- package/dist/signature/index.d.ts.map +1 -0
- package/dist/signature/index.js +5 -0
- package/dist/signature/index.js.map +1 -0
- package/dist/signature/module.d.ts +39 -0
- package/dist/signature/module.d.ts.map +1 -0
- package/dist/signature/module.js +111 -0
- package/dist/signature/module.js.map +1 -0
- package/dist/signature/tool.d.ts +137 -0
- package/dist/signature/tool.d.ts.map +1 -0
- package/dist/signature/tool.js +677 -0
- package/dist/signature/tool.js.map +1 -0
- package/dist/signature/types.d.ts +259 -0
- package/dist/signature/types.d.ts.map +1 -0
- package/dist/signature/types.js +69 -0
- package/dist/signature/types.js.map +1 -0
- package/docs/README.md +19 -17
- package/docs/batch.md +223 -0
- package/docs/documents/README.md +152 -6
- package/docs/pi-extension.md +42 -0
- package/docs/providers.md +3 -1
- package/docs/signature/README.md +311 -0
- package/docs/signature/docusign.md +139 -0
- package/docs/signature/dropbox-sign.md +76 -0
- package/docs/signature/pandadoc.md +76 -0
- package/package.json +16 -6
- package/skills/documents/SKILL.md +17 -1
- package/skills/signature/SKILL.md +97 -0
package/docs/batch.md
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# Batch runs
|
|
2
|
+
|
|
3
|
+
Run one agent over many prompts. Each prompt is answered in its own fresh
|
|
4
|
+
session, and each answer is recorded as soon as it finishes. Batches suit work
|
|
5
|
+
where you have many independent questions for the same agent: summarizing a
|
|
6
|
+
set of documents, classifying records, or extracting fields from a backlog of
|
|
7
|
+
text.
|
|
8
|
+
|
|
9
|
+
A batch can be stopped at any time and picks up where it left off: prompts
|
|
10
|
+
that already succeeded are skipped, and everything else runs again.
|
|
11
|
+
|
|
12
|
+
## Quick start
|
|
13
|
+
|
|
14
|
+
Pass the prompts in, and get the answers back:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { resolveRecipe } from "@introspection-ai/recipes";
|
|
18
|
+
import {
|
|
19
|
+
createInProcessRunController,
|
|
20
|
+
runBatch,
|
|
21
|
+
} from "@introspection-ai/recipes/batch";
|
|
22
|
+
|
|
23
|
+
const recipe = resolveRecipe({ recipeDir: "./my-recipe" });
|
|
24
|
+
const controller = createInProcessRunController({
|
|
25
|
+
recipe,
|
|
26
|
+
cwd: process.cwd(),
|
|
27
|
+
concurrency: 4,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const { results } = await runBatch({
|
|
31
|
+
agent: "summarize",
|
|
32
|
+
input: [
|
|
33
|
+
{
|
|
34
|
+
custom_id: "doc-1",
|
|
35
|
+
prompt: "Summarize this report in three sentences: ...",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
custom_id: "doc-2",
|
|
39
|
+
prompt: "Summarize this report in three sentences: ...",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
controller,
|
|
43
|
+
concurrency: 4,
|
|
44
|
+
});
|
|
45
|
+
await controller.shutdown();
|
|
46
|
+
|
|
47
|
+
for (const line of results) {
|
|
48
|
+
console.log(line.custom_id, line.result.output);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Everything runs in your process, with your Recipe's model settings and
|
|
53
|
+
provider credentials. Nothing is uploaded anywhere.
|
|
54
|
+
|
|
55
|
+
## Resumable batches
|
|
56
|
+
|
|
57
|
+
For a large batch, give it a `directory`. Results are then written to
|
|
58
|
+
`<directory>/results.jsonl` as each prompt finishes, and running the same batch
|
|
59
|
+
again only runs what is left:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
const outcome = await runBatch({
|
|
63
|
+
agent: "summarize",
|
|
64
|
+
input: "prompts.jsonl", // read from the directory; inline prompts work too
|
|
65
|
+
directory: "./batch",
|
|
66
|
+
controller,
|
|
67
|
+
});
|
|
68
|
+
console.log(outcome);
|
|
69
|
+
// { total: 1000, already_completed: 600, completed: 400, failed: 0, not_started: 0, stopped: false, results: [...] }
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Without a `directory`, results are kept in memory and returned, and the batch
|
|
73
|
+
cannot resume after the process exits.
|
|
74
|
+
|
|
75
|
+
## Streaming results
|
|
76
|
+
|
|
77
|
+
To act on each answer as it arrives (write it to your own database, update a
|
|
78
|
+
UI), pass `onResult`:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
await runBatch({
|
|
82
|
+
agent: "summarize",
|
|
83
|
+
input,
|
|
84
|
+
controller,
|
|
85
|
+
onResult: async (line) => {
|
|
86
|
+
await saveSummary(line.custom_id, line.result.output); // your own code
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`onResult` is called once per prompt, in the order prompts finish.
|
|
92
|
+
|
|
93
|
+
## Input format
|
|
94
|
+
|
|
95
|
+
`input` is either an array of prompts, or the path (or `file:` URL) of a JSONL
|
|
96
|
+
file with one prompt per line. Each prompt has:
|
|
97
|
+
|
|
98
|
+
| Field | Required | Meaning |
|
|
99
|
+
| ----------- | -------- | -------------------------------------------------------------------------- |
|
|
100
|
+
| `custom_id` | yes | Your id for the prompt. It must be unique in the batch. |
|
|
101
|
+
| `prompt` | yes | What the agent is asked. |
|
|
102
|
+
| `metadata` | no | Any object. It is copied onto the prompt's result as is, for your own use. |
|
|
103
|
+
|
|
104
|
+
As a file:
|
|
105
|
+
|
|
106
|
+
```jsonl
|
|
107
|
+
{"custom_id": "doc-1", "prompt": "Summarize this report in three sentences: ..."}
|
|
108
|
+
{"custom_id": "doc-2", "prompt": "Summarize this report in three sentences: ...", "metadata": {"source": "acme"}}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
A malformed prompt or a repeated `custom_id` stops the batch before anything
|
|
112
|
+
runs, and the error says which one.
|
|
113
|
+
|
|
114
|
+
## Results format
|
|
115
|
+
|
|
116
|
+
Each result has the same shape as Anthropic's Message Batches results:
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"custom_id": "doc-1",
|
|
121
|
+
"result": {
|
|
122
|
+
"type": "succeeded",
|
|
123
|
+
"output": "The report finds ...",
|
|
124
|
+
"run_id": "..."
|
|
125
|
+
},
|
|
126
|
+
"batch": { "record_index": 0, "input_sha256": "...", "attempts": 1 },
|
|
127
|
+
"metadata": { "source": "acme" }
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
- `result.type` is `succeeded`, `errored` (with `result.error.message`), or
|
|
132
|
+
`canceled` (the prompt was still running when the batch was cancelled).
|
|
133
|
+
- `batch.record_index` is the prompt's position in the input, and
|
|
134
|
+
`batch.attempts` is how many times it ran.
|
|
135
|
+
- `runBatch` returns the latest result for every prompt, in input order. In a
|
|
136
|
+
results file, a prompt that runs again is appended again, so read the last
|
|
137
|
+
line for each `custom_id`.
|
|
138
|
+
|
|
139
|
+
## Options
|
|
140
|
+
|
|
141
|
+
| Option | Default | Meaning |
|
|
142
|
+
| --------------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
143
|
+
| `agent` | required | The Recipe agent that answers each prompt. |
|
|
144
|
+
| `input` | required | The prompts, or a JSONL file of them. |
|
|
145
|
+
| `controller` | required | Runs each prompt: `createInProcessRunController`, or your own `AgentRunController`. |
|
|
146
|
+
| `directory` | none | Where results are written and resumed from. A relative `input` path is read from here too. |
|
|
147
|
+
| `output_name` | `results.jsonl` | The results file name in `directory`. |
|
|
148
|
+
| `concurrency` | 8 (max 32) | How many prompts run at once. |
|
|
149
|
+
| `max_attempts` | 3 (max 5) | How many times a rate-limited prompt is tried. Other failures are not retried. |
|
|
150
|
+
| `deadline_ms` | none | Stop starting new prompts after this long. Prompts not started run next time. |
|
|
151
|
+
| `output_format` | `text` | With `json`, an answer that is not valid JSON is sent back to the agent to fix, up to two times. |
|
|
152
|
+
| `signal` | none | Abort it to stop gracefully. |
|
|
153
|
+
| `onResult` | none | Called with each result as it is recorded. |
|
|
154
|
+
| `onProgress` | none | Called with the counts after every prompt and when the batch stops. |
|
|
155
|
+
| `batch_id` | derived | Names the batch in each prompt's conversation id. Derived from the results file with a `directory`, so a resumed batch keeps its ids; random without one. |
|
|
156
|
+
| `baggage` | none | Extra OpenTelemetry baggage set around each prompt's session: an object, or a function of the prompt. |
|
|
157
|
+
|
|
158
|
+
Unknown options are rejected, so a typo fails fast instead of being ignored.
|
|
159
|
+
|
|
160
|
+
## Stopping and resuming
|
|
161
|
+
|
|
162
|
+
- **Abort the `signal`** to stop gracefully. No new prompts start, the ones
|
|
163
|
+
already running finish and are recorded, and the rest are counted as
|
|
164
|
+
`not_started`.
|
|
165
|
+
- **Stop the process outright** and only the prompts that were running are
|
|
166
|
+
lost; with a `directory`, they run again next time.
|
|
167
|
+
- **Run again with the same `directory`** and the batch skips every prompt
|
|
168
|
+
whose last result succeeded for the same agent and prompt text. A prompt
|
|
169
|
+
whose text or agent changed runs again, as does any prompt that failed.
|
|
170
|
+
|
|
171
|
+
When the provider rate-limits a prompt, the batch waits and retries it, and
|
|
172
|
+
lowers its concurrency until requests succeed again.
|
|
173
|
+
|
|
174
|
+
## Traces
|
|
175
|
+
|
|
176
|
+
Each prompt runs as its own conversation, with the id
|
|
177
|
+
`<batch_id>:<index>`. That id is on the prompt's result as
|
|
178
|
+
`result.conversation_id`, so a result and its trace join on it.
|
|
179
|
+
|
|
180
|
+
The batch sets the id as OpenTelemetry baggage (`gen_ai.conversation.id`)
|
|
181
|
+
around the prompt's session. A Recipes session takes its conversation id from
|
|
182
|
+
that baggage, unless its `otel.meta` names one, and so do the subagents it
|
|
183
|
+
starts. Any other baggage entries, including your own from `baggage`, are added
|
|
184
|
+
to every span the session records:
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
await runBatch({
|
|
188
|
+
agent: "summarize",
|
|
189
|
+
input,
|
|
190
|
+
controller,
|
|
191
|
+
baggage: (line) => ({ "acme.document_id": line.custom_id }),
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Recipes uses your process's own `@opentelemetry/api` (a peer dependency), so it
|
|
196
|
+
sees the context and baggage your SDK registers. Baggage only flows through `await` when your OpenTelemetry SDK has registered
|
|
197
|
+
an async context manager, which the Node SDK does by default. If your SDK also
|
|
198
|
+
propagates W3C baggage on outgoing HTTP requests, these entries are sent with
|
|
199
|
+
those requests too, so keep them to ids rather than anything sensitive.
|
|
200
|
+
|
|
201
|
+
## Agents that use subagents
|
|
202
|
+
|
|
203
|
+
Each prompt is one run of the controller. If the batch's agent starts
|
|
204
|
+
subagents of its own, those count against the same controller, so give the
|
|
205
|
+
controller a higher `concurrency` than the batch's. If the two are equal, every
|
|
206
|
+
subagent is refused while all the batch's slots are busy.
|
|
207
|
+
|
|
208
|
+
## Hosting batches
|
|
209
|
+
|
|
210
|
+
Applications that run batches for others can take full control with
|
|
211
|
+
`runBatchWith(params, deps)`. It takes validated settings (`parseBatchParams`)
|
|
212
|
+
and lets you supply each part yourself:
|
|
213
|
+
|
|
214
|
+
- **`results`**: where results are kept. `jsonlResults` appends to one file;
|
|
215
|
+
`ResultShards` closes finished results into numbered files that never change
|
|
216
|
+
once written, so each only needs copying somewhere durable once.
|
|
217
|
+
- **`files`**: replaces the local file system with your own storage.
|
|
218
|
+
- **`lineScope`**: gives each prompt its own conversation id and wraps its
|
|
219
|
+
session, so its full exchange can be read back later.
|
|
220
|
+
- **`cancel`**: a second signal for when a stopping batch can wait no longer;
|
|
221
|
+
prompts still running are recorded as `canceled` and run again next time.
|
|
222
|
+
|
|
223
|
+
None of these are needed to run a batch with `runBatch`.
|
package/docs/documents/README.md
CHANGED
|
@@ -16,7 +16,8 @@ Two properties follow, as for [channels](../channels/README.md):
|
|
|
16
16
|
- **The original is never changed.** Every write takes the document to read
|
|
17
17
|
(`path`) and a new file under `outputs/` to save (`output`). Later calls
|
|
18
18
|
edit that saved file in place by passing it as `path`. The tool refuses to
|
|
19
|
-
write outside `outputs/` or over a file it did not save.
|
|
19
|
+
write outside `outputs/` or over a file it did not save. `convert` follows
|
|
20
|
+
the same rule: it reads one file and saves a new one in another format.
|
|
20
21
|
|
|
21
22
|
Agents select `tools: [documents]`.
|
|
22
23
|
|
|
@@ -207,6 +208,7 @@ doesn't ship fails when the Recipe loads, with the names it does ship.
|
|
|
207
208
|
| `respond` | `path`, `output?`, `author`, `responses[]` | `respond` | not registered |
|
|
208
209
|
| `remove_section` | `path`, `output?`, `author`, `from`, `through`, `keep?`, `rationale` | `removeSection` | not registered |
|
|
209
210
|
| `render` | `path`, `pages?` | `render` | With a browser, the full page light and dark and each chart as its own element screenshot, at 2x; without one, each inline `<svg>` chart through resvg, naming what it could not draw. `pages` picks charts. |
|
|
211
|
+
| `convert` | `path`, `output`, `pages?` | `export` on the format of `path`, `create` on the format of `output` | A new file in the output's format, rebuilt from the source's headings, paragraphs and tables. See [PDF to Word](#pdf-to-word-convert). |
|
|
210
212
|
|
|
211
213
|
An edit is `{ op: "replace" | "delete" | "insert_after", quote, paragraph?,
|
|
212
214
|
near?, occurrence?, new?, rationale }`. A response is `{ action: "accept" |
|
|
@@ -228,6 +230,7 @@ candidate paragraphs. It never returns the whole document; `read` does that.
|
|
|
228
230
|
| `respond` | Accept or reject by change number (tracked moves resolve as a pair), reply, or counter | not registered | not registered |
|
|
229
231
|
| `remove_section` | Strikes the paragraphs, leaves `Reserved.` after `keep`, keeps numbering | not registered | not registered |
|
|
230
232
|
| `render` | not registered | PNG files of pages, at most 10 per call; returns their paths for Pi's `read` tool | With a browser, the full page light and dark and each chart as its own element screenshot, at 2x; without one, each inline `<svg>` chart through resvg, naming what it could not draw. `pages` picks charts. |
|
|
233
|
+
| `convert` | `create`: a new `.docx` from an outline, with Heading 1–3, Normal paragraphs and Table Grid tables | `export`: the outline of the pages' text, as headings, paragraphs and, with the `tables` extra, tables | not registered |
|
|
231
234
|
|
|
232
235
|
### docx: revise or propose_edits
|
|
233
236
|
|
|
@@ -241,10 +244,11 @@ sits inside someone else's change. A revision whose text is unchanged becomes a
|
|
|
241
244
|
comment on that paragraph, and a revision without a rationale fails alone rather
|
|
242
245
|
than failing the batch's schema check.
|
|
243
246
|
|
|
244
|
-
`compare` is used only when its result keeps the body's block structure
|
|
245
|
-
paper-docx 0.2.0 inserts empty paragraphs for some
|
|
246
|
-
|
|
247
|
-
|
|
247
|
+
`compare` is used only when its result keeps the body's block structure and
|
|
248
|
+
each table's rows and cells: paper-docx 0.2.0 inserts empty paragraphs for some
|
|
249
|
+
multi-paragraph batches, and rebuilds a table whose cells it changes by deleting
|
|
250
|
+
and re-inserting whole rows, the other party's cells included. Either would move
|
|
251
|
+
paragraph ids, so such a result is discarded for the tracked path.
|
|
248
252
|
|
|
249
253
|
### docx: anchors
|
|
250
254
|
|
|
@@ -306,7 +310,8 @@ Every PDF `read` starts with `Path:` and the route it took:
|
|
|
306
310
|
directory, or under `pagesDir` when the host passes one to
|
|
307
311
|
`registerDocumentTools`.
|
|
308
312
|
|
|
309
|
-
PDFs are never changed: every write command is absent for `.pdf`.
|
|
313
|
+
PDFs are never changed: every write command is absent for `.pdf`. To redline
|
|
314
|
+
one, `convert` it to Word (below).
|
|
310
315
|
|
|
311
316
|
#### The `tables` extra
|
|
312
317
|
|
|
@@ -324,10 +329,104 @@ then `uv lock`. The helper imports pdfplumber only when a read asks for tables,
|
|
|
324
329
|
and nothing is fetched at run time. A profile for contract or pricing work may
|
|
325
330
|
recommend the extra; a Recipe that only reads briefs can leave it out.
|
|
326
331
|
|
|
332
|
+
### PDF to Word: `convert`
|
|
333
|
+
|
|
334
|
+
A PDF can't hold tracked changes, so to redline one the agent converts it to
|
|
335
|
+
Word and marks up the Word file like any other:
|
|
336
|
+
|
|
337
|
+
```text
|
|
338
|
+
documents convert { path: "msa.pdf", output: "outputs/msa.docx" }
|
|
339
|
+
documents read { path: "outputs/msa.docx" }
|
|
340
|
+
documents revise { path: "outputs/msa.docx", author, revisions }
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
The converted file is one this tool saved, so later commands edit it in place
|
|
344
|
+
with no `output`, and its tracked changes are the only markup in it.
|
|
345
|
+
|
|
346
|
+
`convert` rebuilds the document's structure, then sets it as the source set
|
|
347
|
+
it. Headings, paragraphs and tables come over as Word headings, paragraphs and
|
|
348
|
+
tables, which is what paragraph ids, quotes and tracked changes need. They
|
|
349
|
+
come over with:
|
|
350
|
+
|
|
351
|
+
- **the formatting of their text:** the body font as the Normal style, and runs
|
|
352
|
+
for what differs (bold, italic, underline, family, size, colour), so a bold
|
|
353
|
+
run-in clause heading stays bold inside its paragraph;
|
|
354
|
+
- **the layout of the page:** page size and margins, line pitch, space before
|
|
355
|
+
each paragraph, centring, and left, hanging and first-line indents, with a
|
|
356
|
+
tab after a clause number or bullet set off by more than a space;
|
|
357
|
+
- **the running header and footer,** as Word's own, with the page number and
|
|
358
|
+
count as fields;
|
|
359
|
+
- **tables as drawn:** ruled or not, their text size, and a bold header row.
|
|
360
|
+
- **filled form fields:** a completed form's values live in its fields, not its
|
|
361
|
+
text, so they are set into the page where the PDF shows them, in the body
|
|
362
|
+
font, and the result counts them so the agent checks each one.
|
|
363
|
+
|
|
364
|
+
The right margin is the one the source wrapped at: past its longest line,
|
|
365
|
+
and short of every word it pushed to the next line. Printed back to PDF, the
|
|
366
|
+
Word file broke 91% of its lines where the original did on a two-page
|
|
367
|
+
statement of work, on the same number of pages, and 90% on a twelve-page one,
|
|
368
|
+
whose text it kept to 98%.
|
|
369
|
+
|
|
370
|
+
Images, columns and drawn lines that underline nothing do not come over, and
|
|
371
|
+
page breaks fall where Word puts them. A converter that reproduces the page,
|
|
372
|
+
such as LibreOffice's PDF import or pdf2docx, places text in positioned boxes
|
|
373
|
+
and line by line. The file looks right but redlines badly, because a sentence
|
|
374
|
+
split across boxes can't be quoted or revised as one paragraph.
|
|
375
|
+
|
|
376
|
+
The work runs in two halves, each in its own format's Python environment, so
|
|
377
|
+
neither environment gains a library and the runtime image needs nothing new:
|
|
378
|
+
|
|
379
|
+
- **The PDF adapter exports an outline.** It reads pypdfium2's characters with
|
|
380
|
+
their positions, fonts, sizes (after the page's scale) and colours, and
|
|
381
|
+
underlines from the thin paths beneath them, and joins them into
|
|
382
|
+
paragraphs. It starts a
|
|
383
|
+
new paragraph at a wider vertical gap, at a change of indent, at a line
|
|
384
|
+
that opens with a clause number such as `1.2`, `(a)` or `(iv)`, or after a
|
|
385
|
+
line the next line's first word would have fit on. A paragraph
|
|
386
|
+
that runs across a page break is joined back, and a word hyphenated at a line
|
|
387
|
+
end is rejoined. Lines repeated at the top or bottom of the pages (running
|
|
388
|
+
headers, footers and page numbers) are dropped. Lines set larger than the
|
|
389
|
+
body text, or bold lines on their own, become headings, the largest (and
|
|
390
|
+
centred before left) at level 1. Columns that line up across two or more
|
|
391
|
+
lines, such as a signature block, become a table. With the `tables`
|
|
392
|
+
extra, pdfplumber's tables become table blocks and their text is left out of
|
|
393
|
+
the paragraphs. Without it, a table's text comes over as paragraphs and the
|
|
394
|
+
result says the extra was missing.
|
|
395
|
+
- **The Word adapter creates the file.** It builds the `.docx` from the
|
|
396
|
+
outline with paper-docx, sets the page, fonts and spacing above, and records
|
|
397
|
+
the source's file name in the file's core properties.
|
|
398
|
+
|
|
399
|
+
The host runs the export, passes the outline to the creating format and
|
|
400
|
+
writes only `output`. That must be a new file under `outputs/`, with the
|
|
401
|
+
extension of a format that creates. The source is never changed.
|
|
402
|
+
|
|
403
|
+
Clause numbers stay as the text the PDF shows, not Word list numbering, so
|
|
404
|
+
they never renumber under an edit.
|
|
405
|
+
|
|
406
|
+
`convert` fails, and writes nothing, when:
|
|
407
|
+
|
|
408
|
+
- **A page in range has no text layer (a scan).** The error names the pages.
|
|
409
|
+
A contract with a page silently missing is worse than none: the agent
|
|
410
|
+
renders those pages and tells the person the PDF needs a text layer (OCR)
|
|
411
|
+
first. OCR is not part of the tool.
|
|
412
|
+
- **The PDF is password-protected,** with the same message as `read`.
|
|
413
|
+
- **The output's format doesn't create files,** or the source's format doesn't
|
|
414
|
+
export. The error names the formats that do.
|
|
415
|
+
|
|
416
|
+
The result reports the pages converted and the counts of headings, paragraphs
|
|
417
|
+
and tables. It also reports how many repeated lines were dropped and whether
|
|
418
|
+
tables were detected, and reminds the agent that the layout was rebuilt.
|
|
419
|
+
|
|
420
|
+
In a `commands` allowlist, `convert` on the PDF declaration allows exporting
|
|
421
|
+
and on the Word declaration allows creating. The command is registered when
|
|
422
|
+
some declared format exports and some creates, and a call needs both of its
|
|
423
|
+
ends allowed.
|
|
424
|
+
|
|
327
425
|
## Limits
|
|
328
426
|
|
|
329
427
|
- `read` returns about 50,000 characters per part; pass the `offset` it gives.
|
|
330
428
|
- A batch takes at most 60 edits or responses.
|
|
429
|
+
- `convert` takes the whole PDF unless `pages` narrows it.
|
|
331
430
|
- Paragraph ids are body-block positions. Edits never add or remove blocks, so
|
|
332
431
|
ids hold for a whole redline; a document edited elsewhere gets new ids.
|
|
333
432
|
- Change numbers for `respond` are positions in the file as read: read again
|
|
@@ -391,6 +490,46 @@ const pdf: RecipeDocumentFormatModule = {
|
|
|
391
490
|
export default pdf;
|
|
392
491
|
```
|
|
393
492
|
|
|
493
|
+
Two optional capabilities connect formats for `convert`. `export` means the
|
|
494
|
+
adapter returns a document's content as a `DocumentOutline`, and `create`
|
|
495
|
+
means it builds a new file from one:
|
|
496
|
+
|
|
497
|
+
```ts
|
|
498
|
+
interface DocumentOutline {
|
|
499
|
+
/** The source's file name, recorded in the new file. */
|
|
500
|
+
source: string;
|
|
501
|
+
font?: { family: string; size: number };
|
|
502
|
+
page?: { width: number; height: number; margins: { top: number; bottom: number; left: number; right: number } };
|
|
503
|
+
line_pitch?: number;
|
|
504
|
+
header?: DocumentRunningLine[]; // `{PAGE}` and `{NUMPAGES}` stand for fields
|
|
505
|
+
footer?: DocumentRunningLine[];
|
|
506
|
+
blocks: DocumentBlock[];
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
type DocumentBlock =
|
|
510
|
+
| { type: "heading"; level: 1 | 2 | 3; text: string; page: number; runs?: DocumentRun[]; /* layout */ }
|
|
511
|
+
| { type: "paragraph"; text: string; page: number; runs?: DocumentRun[]; /* layout */ }
|
|
512
|
+
| { type: "table"; rows: string[][]; page: number; ruled?: boolean; size?: number; header?: boolean };
|
|
513
|
+
|
|
514
|
+
// layout: align?: "center", indent?, first_line?, space_before? (points)
|
|
515
|
+
// DocumentRun: { text, bold?, italic?, underline?, family?, size?, color? }, naming only what differs from `font`
|
|
516
|
+
|
|
517
|
+
interface DocumentAdapter {
|
|
518
|
+
// ...
|
|
519
|
+
export?(ctx: DocumentAdapterContext, input: DocumentExportInput): Promise<DocumentExport>;
|
|
520
|
+
create?(ctx: DocumentAdapterContext, input: DocumentCreateInput): Promise<DocumentResult>;
|
|
521
|
+
}
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
`text` always holds a block's whole text, so a creating format that ignores
|
|
525
|
+
formatting still builds a correct file. `DocumentExport` is a `DocumentResult`
|
|
526
|
+
with the `outline` beside its `text`.
|
|
527
|
+
A Python helper answers with an `outline` key beside `text` and `details`. The
|
|
528
|
+
host keeps the outline out of what the model sees and passes the export's
|
|
529
|
+
`text` (its notes, such as a missing extra) through with the create's result.
|
|
530
|
+
Both capabilities are additive, so the contract stays at `apiVersion` 1. A
|
|
531
|
+
host that predates them loads such a format without `convert`.
|
|
532
|
+
|
|
394
533
|
`apiVersion` names the contract the format was written against; the host
|
|
395
534
|
refuses a different one, naming the package, both versions and the fix.
|
|
396
535
|
`createDocumentFormatModule` from `@introspection-ai/recipes/documents` builds
|
|
@@ -420,6 +559,13 @@ a pinned one.
|
|
|
420
559
|
A skill that teaches a format library, such as Paper's `docx` skill, is a
|
|
421
560
|
dependency of the Recipe that uses it, installed when the runtime is baked.
|
|
422
561
|
|
|
562
|
+
## After review: sending for signature
|
|
563
|
+
|
|
564
|
+
The document tools never send a file anywhere. Once a person has reviewed the
|
|
565
|
+
redline and every change is resolved, the [signature tool](../signature/README.md)
|
|
566
|
+
sends the final `.docx` under `outputs/` for e-signature, and refuses one that
|
|
567
|
+
still has tracked changes or comments.
|
|
568
|
+
|
|
423
569
|
## Format pages
|
|
424
570
|
|
|
425
571
|
- Word: this page; `packages/documents/docx/README.md`.
|
package/docs/pi-extension.md
CHANGED
|
@@ -158,6 +158,48 @@ available in Pi's interactive terminal, ...` so the model can tell the user
|
|
|
158
158
|
where to look. If a Recipe extension registers its own `show_artifact`, the
|
|
159
159
|
host keeps it and registers neither the built-in tool nor `/recipe view`.
|
|
160
160
|
|
|
161
|
+
### Binary artifacts in a browser host
|
|
162
|
+
|
|
163
|
+
A host with `storeArtifact` can also show DOCX, PDF and common image files
|
|
164
|
+
through the same `show_artifact({ path })` tool. The host receives the original
|
|
165
|
+
`Uint8Array` and MIME type, persists it, and returns its file id. The recorded
|
|
166
|
+
result carries `kind: "file"`, that id and byte count, with empty `content`;
|
|
167
|
+
no binary payload is put in the conversation. Browser hosts render those bytes
|
|
168
|
+
with their file preview component, including after a conversation reload.
|
|
169
|
+
|
|
170
|
+
The existing working-directory and symlink boundary applies, with a 25 MiB cap.
|
|
171
|
+
Binary `ref` and text `diff` requests are refused. Without a binary-capable
|
|
172
|
+
`storeArtifact` implementation the host must not opt into this contract; the
|
|
173
|
+
terminal cannot render binary files. Hosts upgrading from the string-only
|
|
174
|
+
callback must handle both `string` and `Uint8Array` content.
|
|
175
|
+
|
|
176
|
+
### Explicit artifact links
|
|
177
|
+
|
|
178
|
+
Hosts resolve explicit Markdown destinations against known artifact references
|
|
179
|
+
with `resolveArtifactLink` from `@introspection-ai/recipes/review`. The resolver
|
|
180
|
+
is shared, browser-safe code; it neither parses prose nor reads or uploads files.
|
|
181
|
+
A local host leaves an unuploaded file's authored path intact. A hosted UI can
|
|
182
|
+
map `file.id` to its file page, map `source` to its pinned repository view, and
|
|
183
|
+
return no URL for `path` so the link opens its existing artifact viewer.
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
const link = resolveArtifactLink("outputs/report.md", artifacts, {
|
|
187
|
+
workspaceRoot: "/workspace",
|
|
188
|
+
file: ({ id }) => `/files/${encodeURIComponent(id)}`,
|
|
189
|
+
path: () => undefined,
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
`artifacts` belongs to the current conversation or selected document, never a
|
|
194
|
+
global basename index. The latest exact workspace-path match wins. `fromPath`
|
|
195
|
+
resolves links relative to a document; absolute paths require `workspaceRoot`
|
|
196
|
+
and cannot escape it. Local `file:` URLs use the same workspace boundary; remote
|
|
197
|
+
file authorities are refused. Percent-encoded filenames and URL fragments are supported.
|
|
198
|
+
External URLs, malformed destinations, query-bearing paths and unknown files
|
|
199
|
+
are left to the host's ordinary link handling. Bare paths, inline code, fenced
|
|
200
|
+
code and images do not invoke this API. Opening a known reference needs no
|
|
201
|
+
additional tool call; persistence remains part of the standard artifact tool.
|
|
202
|
+
|
|
161
203
|
### Reviewing several files
|
|
162
204
|
|
|
163
205
|
List `review_artifacts` and the agent can ask the user to review several
|
package/docs/providers.md
CHANGED
|
@@ -16,6 +16,7 @@ versioned contract for the providers behind them:
|
|
|
16
16
|
| `search` | `web_search` | tavily, exa, brave, keenable, parallel, perplexity |
|
|
17
17
|
| `productivity` | `mail`, `calendar`, `drive` | google, microsoft |
|
|
18
18
|
| `issues` | `issues` | linear, jira, introspection |
|
|
19
|
+
| `signature` | `signature` | docusign, dropbox-sign, pandadoc |
|
|
19
20
|
|
|
20
21
|
A **provider module** implements one family's contract: `{ kind, apiVersion,
|
|
21
22
|
id, capabilities, … }` plus the family's calls (`search` for search,
|
|
@@ -52,7 +53,7 @@ dependency; nothing is loaded from a file in the Recipe at run time.
|
|
|
52
53
|
|
|
53
54
|
| Source | Resolves to |
|
|
54
55
|
| --- | --- |
|
|
55
|
-
| none | the first-party package: `@introspection-ai/recipe-<family>-<id>`, or the family's bundle (`@introspection-ai/recipe-search`, `@introspection-ai/recipe-issues`) |
|
|
56
|
+
| none | the first-party package: `@introspection-ai/recipe-<family>-<id>`, or the family's bundle (`@introspection-ai/recipe-search`, `@introspection-ai/recipe-issues`, `@introspection-ai/recipe-signature`) |
|
|
56
57
|
| `package` | an installed package by name, such as `@acme/recipe-search`, which the Recipe lists in `dependencies` with a version, never only as a peer |
|
|
57
58
|
|
|
58
59
|
A provider kept with the Recipe's own code is a local package inside the
|
|
@@ -225,6 +226,7 @@ the adapter's tests run against a captured tool list.
|
|
|
225
226
|
| `search` | the fixed `SEARCH_PROVIDER_IDS` filter goes; `pi.search` is added; `recipe-search` serves the first-party providers through the shared loader |
|
|
226
227
|
| `productivity` | gains the `package` source; loads through the shared loader |
|
|
227
228
|
| `issues` | new: the contract and the tool in Recipes, and `@introspection-ai/recipe-issues` with `linear`, `jira` and `introspection` |
|
|
229
|
+
| `signature` | new: the contract and the tool in Recipes, and `@introspection-ai/recipe-signature` with `docusign`, `dropbox-sign` and `pandadoc`, each an MCP adapter; one provider per Recipe ([signature](signature/README.md)) |
|
|
228
230
|
|
|
229
231
|
The contract version of each family stays separate, so a breaking change to one
|
|
230
232
|
family's contract does not bump another's.
|