iagenify 0.3.3 → 0.4.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/README.md +385 -360
- package/dist/index.cjs +96 -20
- package/dist/index.js +96 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
# IaGenify SDK
|
|
2
|
-
|
|
3
|
-
Client SDK pour l'API IaGenify — compatible Node.js, Browser, et Cloudflare Workers.
|
|
4
|
-
|
|
1
|
+
# IaGenify SDK
|
|
2
|
+
|
|
3
|
+
Client SDK pour l'API IaGenify — compatible Node.js, Browser, et Cloudflare Workers.
|
|
4
|
+
|
|
5
5
|
> Après une modification du SDK, exécutez `npm run build` avant de le consommer dans une application.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install iagenify
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
### Créer un assistant session
|
|
16
|
-
|
|
17
|
-
```js
|
|
18
|
-
import { IaGenify } from "iagenify";
|
|
19
|
-
|
|
20
|
-
const api = new IaGenify({ apiKey: "ia_..." });
|
|
21
|
-
|
|
22
|
-
const assistant = await api.models.create({
|
|
23
|
-
model: "nvidia/nemotron-3-nano-omni-30b-a3b-reasoning",
|
|
24
|
-
settings: { role: "Expert coder", instructions: "Answer briefly" },
|
|
25
|
-
schema: { type: "object", properties: { code: { type: "string" }, explanation: { type: "string" } } },
|
|
26
|
-
memory: true,
|
|
27
|
-
});
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### Générer
|
|
31
|
-
|
|
32
|
-
```js
|
|
33
|
-
const r1 = await assistant.generate({
|
|
34
|
-
inputs: [{ type: "text", content: "Write a sort function" }],
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const r2 = await assistant.generate({
|
|
38
|
-
inputs: [{ type: "text", content: "In Python" }], // memory retains context
|
|
39
|
-
outputs: [{ type: "text" }],
|
|
40
|
-
});
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Session data
|
|
44
|
-
|
|
45
|
-
```js
|
|
46
|
-
console.log(assistant.data);
|
|
47
|
-
// { id, model, settings, schema, memory, createdAt }
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### Historique
|
|
51
|
-
|
|
52
|
-
```js
|
|
53
|
-
const history = await assistant.getHistory();
|
|
54
|
-
```
|
|
55
|
-
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install iagenify
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Créer un assistant session
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { IaGenify } from "iagenify";
|
|
19
|
+
|
|
20
|
+
const api = new IaGenify({ apiKey: "ia_..." });
|
|
21
|
+
|
|
22
|
+
const assistant = await api.models.create({
|
|
23
|
+
model: "nvidia/nemotron-3-nano-omni-30b-a3b-reasoning",
|
|
24
|
+
settings: { role: "Expert coder", instructions: "Answer briefly" },
|
|
25
|
+
schema: { type: "object", properties: { code: { type: "string" }, explanation: { type: "string" } } },
|
|
26
|
+
memory: true,
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Générer
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
const r1 = await assistant.generate({
|
|
34
|
+
inputs: [{ type: "text", content: "Write a sort function" }],
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const r2 = await assistant.generate({
|
|
38
|
+
inputs: [{ type: "text", content: "In Python" }], // memory retains context
|
|
39
|
+
outputs: [{ type: "text" }],
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Session data
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
console.log(assistant.data);
|
|
47
|
+
// { id, model, settings, schema, memory, createdAt }
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Historique
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
const history = await assistant.getHistory();
|
|
54
|
+
```
|
|
55
|
+
|
|
56
56
|
### Nettoyer
|
|
57
57
|
|
|
58
58
|
```js
|
|
59
59
|
await assistant.destroy();
|
|
60
60
|
```
|
|
61
|
-
|
|
62
|
-
### Domaines
|
|
63
|
-
|
|
64
|
-
```js
|
|
65
|
-
// Extensions prises en charge par le registrar connecté à IaGenify
|
|
66
|
-
const tlds = await api.domains.tlds();
|
|
67
|
-
|
|
68
|
-
// Recherche de noms. Passez les extensions souhaitées pour cibler le résultat.
|
|
69
|
-
const results = await api.domains.search("faysal", { tlds: ["online", "com"] });
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
La recherche ne réserve pas le nom. L’achat et le paiement se font depuis l’espace IaGenify connecté.
|
|
61
|
+
|
|
62
|
+
### Domaines
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
// Extensions prises en charge par le registrar connecté à IaGenify
|
|
66
|
+
const tlds = await api.domains.tlds();
|
|
67
|
+
|
|
68
|
+
// Recherche de noms. Passez les extensions souhaitées pour cibler le résultat.
|
|
69
|
+
const results = await api.domains.search("faysal", { tlds: ["online", "com"] });
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
La recherche ne réserve pas le nom. L’achat et le paiement se font depuis l’espace IaGenify connecté.
|
|
73
73
|
|
|
74
74
|
### Hosts
|
|
75
75
|
|
|
@@ -97,300 +97,325 @@ await endpoint.deploy({ code: 'export default { async fetch() { return new Respo
|
|
|
97
97
|
|
|
98
98
|
Express, Fastify, Nest et Next SSR demandent un serveur Node permanent : ils ne sont pas encore pris en charge par `Hosts`, et le SDK les refuse avant envoi. Exécutez le build localement ; le SDK publie le résultat et exclut toujours `.env`, `.git/`, `node_modules/` et `.DS_Store`.
|
|
99
99
|
|
|
100
|
+
### Courriel (0.4.0)
|
|
101
|
+
|
|
102
|
+
Envoyer depuis une boîte du compte, avec HTML, Cci et pièces jointes — la forme de nodemailer :
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
const box = await api.mail.get("commandes@my-company.example");
|
|
106
|
+
const sent = await box.send({
|
|
107
|
+
to: ["client@acme.com"],
|
|
108
|
+
bcc: ["compta@my-company.example"],
|
|
109
|
+
subject: "Votre commande",
|
|
110
|
+
html: '<img src="cid:logo" alt="Logo" width="160"><p>Merci pour votre commande.</p>',
|
|
111
|
+
text: "Merci pour votre commande.", // repli texte, optionnel
|
|
112
|
+
attachments: [
|
|
113
|
+
{ filename: "logo.png", content: pngBuffer, cid: "logo" }, // image incorporée
|
|
114
|
+
{ filename: "facture.pdf", content: pdfBuffer, contentType: "application/pdf" },
|
|
115
|
+
{ filename: "devis.pdf", path: "./devis.pdf" }, // Node seulement
|
|
116
|
+
],
|
|
117
|
+
});
|
|
118
|
+
// → { id, messageId, accepted, rejected, attachments: [{ filename, size, contentType, inline }], relay }
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`content` accepte Buffer, Uint8Array, ArrayBuffer, Blob ou chaîne (`encoding: "base64"` pour du base64). 25 Mo de
|
|
122
|
+
pièces au total, 20 pièces au plus, exécutables refusés, `cid` unique. **`replyTo` désigne le message auquel on
|
|
123
|
+
répond (le fil)**, pas une adresse de réponse.
|
|
124
|
+
|
|
100
125
|
### Agent local (runtime `"local"`)
|
|
101
|
-
|
|
102
|
-
Un agent qui travaille sur l'ordinateur, comme un assistant de code : il planifie, lit, cherche, modifie les
|
|
103
|
-
fichiers de `~/.iagenify/files`, exécute des commandes et crée des médias. La boucle tourne dans le SDK ; le serveur
|
|
104
|
-
ne sert que les tours de modèle (`api.models.turn`).
|
|
105
|
-
|
|
106
|
-
```js
|
|
107
|
-
const pc = await api.storage.get()
|
|
108
|
-
const agent = api.agents.create({
|
|
109
|
-
runtime: "local",
|
|
110
|
-
machine: pc,
|
|
111
|
-
model: "gemini-3.5-flash",
|
|
112
|
-
tools: api.tools.all,
|
|
113
|
-
mode: "ask", // ask · auto · plan · full
|
|
114
|
-
onPermission: async ({ tool, args }) => "once", // "once" | "always" | "deny"
|
|
115
|
-
onQuestion: async ({ question, options }) => options[0], // réponses à ask_user
|
|
116
|
-
fallbackModels: ["gemini-3.5-flash"], // si le modèle échoue
|
|
117
|
-
thinking: "low", // minimal · low · medium · high
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
const result = await agent.run({
|
|
121
|
-
inputs: [{ type: "text", content: "Crée un script qui calcule la moyenne, exécute-le et note le résultat." }],
|
|
122
|
-
onEvent: (e) => console.log(e.type, e.tool ?? "", e.summary ?? ""),
|
|
123
|
-
})
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
+
|
|
127
|
+
Un agent qui travaille sur l'ordinateur, comme un assistant de code : il planifie, lit, cherche, modifie les
|
|
128
|
+
fichiers de `~/.iagenify/files`, exécute des commandes et crée des médias. La boucle tourne dans le SDK ; le serveur
|
|
129
|
+
ne sert que les tours de modèle (`api.models.turn`).
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
const pc = await api.storage.get()
|
|
133
|
+
const agent = api.agents.create({
|
|
134
|
+
runtime: "local",
|
|
135
|
+
machine: pc,
|
|
136
|
+
model: "gemini-3.5-flash",
|
|
137
|
+
tools: api.tools.all,
|
|
138
|
+
mode: "ask", // ask · auto · plan · full
|
|
139
|
+
onPermission: async ({ tool, args }) => "once", // "once" | "always" | "deny"
|
|
140
|
+
onQuestion: async ({ question, options }) => options[0], // réponses à ask_user
|
|
141
|
+
fallbackModels: ["gemini-3.5-flash"], // si le modèle échoue
|
|
142
|
+
thinking: "low", // minimal · low · medium · high
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
const result = await agent.run({
|
|
146
|
+
inputs: [{ type: "text", content: "Crée un script qui calcule la moyenne, exécute-le et note le résultat." }],
|
|
147
|
+
onEvent: (e) => console.log(e.type, e.tool ?? "", e.summary ?? ""),
|
|
148
|
+
})
|
|
149
|
+
```
|
|
150
|
+
|
|
126
151
|
### Skills et sous-agents
|
|
127
|
-
|
|
128
|
-
Ils appartiennent au **compte** (P73) et vous suivent donc sur tous vos appareils, y compris là où il n'y a pas de
|
|
129
|
-
disque. Le dossier `~/.iagenify/skills` et `agents` d'un ordinateur reste lu en plus, au format de Claude Code : un
|
|
130
|
-
fichier copié depuis Claude fonctionne tel quel. Chaque élément dit d'où il vient (`source`), et sur un même nom
|
|
131
|
-
c'est celui du compte qui vaut. L'agent les lit au début de chaque run : un skill est chargé quand une demande
|
|
132
|
-
correspond, un sous-agent reçoit du travail par l'outil `task` (plusieurs en parallèle).
|
|
133
|
-
|
|
134
|
-
```js
|
|
135
|
-
await api.agents.skills.save({ name: "legal-review", description: "Review legal documents: parties, dates, risks", content: "# Steps\n1. …" })
|
|
136
|
-
await api.agents.subagents.save({ name: "scout", description: "Lit et rapporte", tools: ["read", "grep"], content: "Tu lis et tu rapportes." })
|
|
137
|
-
await api.agents.skills.list() // [{ name, description, source: "account" | "computer" }]
|
|
138
|
-
|
|
139
|
-
await agent.run({ inputs: [{ type: "text", content: "/legal-review Legal/contrat.pdf" }], onEvent }) // événements imbriqués : parentId
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### Serveurs MCP
|
|
143
|
-
|
|
144
|
-
Le SDK est un **client MCP** : n'importe quel serveur du protocole fonctionne, sans adaptateur à écrire. Seuls les
|
|
145
|
-
outils autorisés à la connexion sont déclarés au modèle — une déclaration coûte des jetons à chaque tour. Leur
|
|
146
|
-
permission est celle du serveur, `exec` par défaut, donc demandée sauf en accès complet.
|
|
147
|
-
|
|
148
|
-
```js
|
|
149
|
-
await api.mcp.connect({
|
|
150
|
-
url: "https://mcp.cloudflare.com/mcp",
|
|
151
|
-
token: process.env.CF_TOKEN,
|
|
152
|
-
tools: ["dns_record_list", "r2_bucket_list"], // sans cette liste, aucun outil n'est activé
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
const agent = api.agents.create({ runtime: "local", machine: pc, model: "gemini-3.5-flash", mcp: ["cloudflare"] })
|
|
156
|
-
// Sans `mcp`, tous les serveurs connectés servent ; `mcp: []` n'en prend aucun.
|
|
157
|
-
|
|
158
|
-
await api.mcp.tools() // les déclarations, pour api.models.turn({ tools }) — MCP sans le moteur
|
|
159
|
-
```
|
|
160
|
-
|
|
152
|
+
|
|
153
|
+
Ils appartiennent au **compte** (P73) et vous suivent donc sur tous vos appareils, y compris là où il n'y a pas de
|
|
154
|
+
disque. Le dossier `~/.iagenify/skills` et `agents` d'un ordinateur reste lu en plus, au format de Claude Code : un
|
|
155
|
+
fichier copié depuis Claude fonctionne tel quel. Chaque élément dit d'où il vient (`source`), et sur un même nom
|
|
156
|
+
c'est celui du compte qui vaut. L'agent les lit au début de chaque run : un skill est chargé quand une demande
|
|
157
|
+
correspond, un sous-agent reçoit du travail par l'outil `task` (plusieurs en parallèle).
|
|
158
|
+
|
|
159
|
+
```js
|
|
160
|
+
await api.agents.skills.save({ name: "legal-review", description: "Review legal documents: parties, dates, risks", content: "# Steps\n1. …" })
|
|
161
|
+
await api.agents.subagents.save({ name: "scout", description: "Lit et rapporte", tools: ["read", "grep"], content: "Tu lis et tu rapportes." })
|
|
162
|
+
await api.agents.skills.list() // [{ name, description, source: "account" | "computer" }]
|
|
163
|
+
|
|
164
|
+
await agent.run({ inputs: [{ type: "text", content: "/legal-review Legal/contrat.pdf" }], onEvent }) // événements imbriqués : parentId
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Serveurs MCP
|
|
168
|
+
|
|
169
|
+
Le SDK est un **client MCP** : n'importe quel serveur du protocole fonctionne, sans adaptateur à écrire. Seuls les
|
|
170
|
+
outils autorisés à la connexion sont déclarés au modèle — une déclaration coûte des jetons à chaque tour. Leur
|
|
171
|
+
permission est celle du serveur, `exec` par défaut, donc demandée sauf en accès complet.
|
|
172
|
+
|
|
173
|
+
```js
|
|
174
|
+
await api.mcp.connect({
|
|
175
|
+
url: "https://mcp.cloudflare.com/mcp",
|
|
176
|
+
token: process.env.CF_TOKEN,
|
|
177
|
+
tools: ["dns_record_list", "r2_bucket_list"], // sans cette liste, aucun outil n'est activé
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
const agent = api.agents.create({ runtime: "local", machine: pc, model: "gemini-3.5-flash", mcp: ["cloudflare"] })
|
|
181
|
+
// Sans `mcp`, tous les serveurs connectés servent ; `mcp: []` n'en prend aucun.
|
|
182
|
+
|
|
183
|
+
await api.mcp.tools() // les déclarations, pour api.models.turn({ tools }) — MCP sans le moteur
|
|
184
|
+
```
|
|
185
|
+
|
|
161
186
|
### Créer un agent réutilisable
|
|
162
|
-
|
|
163
|
-
```js
|
|
164
|
-
const main = await api.models.create({ model: "gemini-3.5-flash", memory: false });
|
|
165
|
-
const image = await api.models.create({ model: "gemini-2.5-flash-image", memory: false });
|
|
166
|
-
|
|
167
|
-
const agent = api.agents.create({
|
|
168
|
-
model: { main, image },
|
|
169
|
-
tools: {
|
|
170
|
-
search: api.tools.search,
|
|
171
|
-
openPage: api.tools.fetch,
|
|
172
|
-
createImage: api.tools.image,
|
|
173
|
-
},
|
|
174
|
-
maxSteps: 8,
|
|
175
|
-
budget: 100,
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
const result = await agent.run({
|
|
179
|
-
inputs: [{ type: "text", content: "Cherche une source puis illustre la réponse." }],
|
|
180
|
-
onStep: (step) => console.log(step),
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
await agent.destroy();
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
La clé de chaque outil est le nom présenté au modèle. Les modèles et stockages
|
|
187
|
-
doivent être des objets déjà obtenus auprès du SDK. `run()` conserve un historique
|
|
188
|
-
léger entre ses appels, diffuse les étapes et accepte un `AbortSignal`. `stop()`
|
|
189
|
-
demande un arrêt coopératif du run courant.
|
|
190
|
-
|
|
191
|
-
## API Reference
|
|
192
|
-
|
|
193
|
-
### `new IaGenify({ apiKey, baseUrl?, storage?, sessionPath?, appName? })`
|
|
194
|
-
|
|
195
|
-
| Option | Default | Description |
|
|
196
|
-
|---|---|---|
|
|
197
|
-
| `apiKey` | — | Clé API (requise si pas de session) |
|
|
198
|
-
| `baseUrl` | `http://localhost:3000` | URL du serveur |
|
|
199
|
-
| `storage` | auto (fs/localStorage/memory) | Stockage session personnalisé |
|
|
200
|
-
| `sessionPath` | `~/.iagenify/session` | Chemin fichier session (Node) |
|
|
201
|
-
| `appName` | — | Nom de l'application |
|
|
202
|
-
|
|
203
|
-
### `api.models.create({ model, settings?, schema?, memory? })` → `AssistantSession`
|
|
204
|
-
|
|
205
|
-
| Champ | Default | Description |
|
|
206
|
-
|---|---|---|
|
|
207
|
-
| `model` | — | Nom du modèle (requis) |
|
|
208
|
-
| `settings` | `{}` | `{ role?, instructions?, negativePrompt?, temperature?, maxOutputTokens? }` — `temperature: 0` est appliqué (sortie déterministe) ; `maxOutputTokens` vaut 8192 par défaut |
|
|
209
|
-
| `schema` | `null` | JSON Schema pour sortie structurée |
|
|
210
|
-
| `memory` | `true` | Conservation du contexte entre appels |
|
|
211
|
-
|
|
212
|
-
### `assistant.generate({ inputs, outputs? })` → `{ outputs, usage, ... }`
|
|
213
|
-
|
|
214
|
-
- `inputs` : tableau de `{ type, content?, url?, mime?, path? }` (requis)
|
|
215
|
-
- `outputs` : tableau de `{ type, description?, schema? }` (optionnel, format imposé par le modèle)
|
|
216
|
-
|
|
217
|
-
Types supportés (`inputs`) : `text`, `image`, `video`, `audio`, `speech`, `passages`
|
|
218
|
-
|
|
219
|
-
### `assistant.data` → `{ id, model, settings, schema, memory, createdAt }`
|
|
220
|
-
|
|
221
|
-
### `assistant.getHistory()` → messages
|
|
222
|
-
|
|
223
|
-
### `assistant.destroy()` → suppression
|
|
224
|
-
|
|
225
|
-
### `api.getUser()` → `{ id, email, credits, pack }`
|
|
226
|
-
|
|
227
|
-
### `api.agents.create({ model, storages?, tools?, outputs?, maxSteps?, budget? })` → `Agent`
|
|
228
|
-
|
|
229
|
-
### `agent.run({ inputs, outputs?, history?, onStep?, signal? })` → `{ text, outputs, steps, artifacts, usage, stopReason }`
|
|
230
|
-
|
|
231
|
-
Chaque étape d'outil de `steps` (et chaque événement `onStep`) porte un `meta`
|
|
232
|
-
qui décrit ce que l'outil a réellement fait :
|
|
233
|
-
|
|
234
|
-
```js
|
|
235
|
-
// search
|
|
236
|
-
{ index: 0, kind: "tool", tool: "search", input, reasoning, summary: "5 résultat(s)", error: "", credits, durationMs,
|
|
237
|
-
meta: { enginesUsed: ["google"], cached: false, results: [{ title, url }] } }
|
|
238
|
-
// fetch
|
|
239
|
-
{ index: 1, kind: "tool", tool: "fetch", input, ..., meta: { url, title } }
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
### `api.tools.search({ query, engines?, maxResults?, recencyDays?, language?, region?, safeSearch? })`
|
|
243
|
-
|
|
244
|
-
```js
|
|
245
|
-
const r = await api.tools.search({ query: "Next.js 16 release notes", engines: ["google"], maxResults: 8, recencyDays: 7 })
|
|
246
|
-
// { ok, query, results: [{ title, url, snippet, engine, engineKey, score, publishedDate? }],
|
|
247
|
-
// enginesUsed, engineErrors, cached, creditsUsed, timing: { durationMs } }
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
| Moteur | Par défaut | Coût |
|
|
251
|
-
|---|---|---|
|
|
252
|
-
| `searxng`, `wiki`, `stackex`, `arxiv` | oui | 1 crédit par recherche |
|
|
253
|
-
| `hackernews`, `forem` | non | inclus dans le crédit de base |
|
|
254
|
-
| `google` | non | 1 + 4 crédits (recherche Google via Vertex) |
|
|
255
|
-
|
|
256
|
-
`engines: ["all"]` interroge tous les moteurs, `google` compris. Une recherche
|
|
257
|
-
sans résultat est remboursée, et un moteur payant en échec n'est pas facturé.
|
|
258
|
-
Dans un agent, passez les moteurs par `options` :
|
|
259
|
-
`tools: { search: { run: api.tools.search, options: { engines: ["google"], maxResults: 8 } } }`.
|
|
260
|
-
|
|
261
|
-
### Fichiers de l'ordinateur (`~/.iagenify/files`)
|
|
262
|
-
|
|
263
|
-
Le stockage d'un ordinateur est gratuit et local : ses fichiers ne quittent jamais la machine.
|
|
264
|
-
|
|
265
|
-
```js
|
|
266
|
-
const pc = await api.storage.get()
|
|
267
|
-
await pc.files.write("Launch plan/brief.md", "# Brief")
|
|
268
|
-
await pc.files.list("Launch plan") // [{ name, path, type: "file" | "folder", size, mimeType, modifiedAt }]
|
|
269
|
-
await pc.files.read("Launch plan/brief.md")
|
|
270
|
-
await pc.files.mkdir("Archive") ; await pc.files.move("Launch plan/brief.md", "Archive/brief.md") ; await pc.files.remove("Archive")
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
Un agent qui reçoit ce stockage en `storages` lit ces fichiers avec `list_documents` / `read_document`, et les
|
|
274
|
-
écrit avec `write_document`, `create_folder`, `move_document`, `delete_document` : le serveur demande l'opération au
|
|
275
|
-
SDK de la machine, qui la fait sur le disque. Une mise à jour garde l'ancienne version dans `.versions`, une
|
|
276
|
-
suppression va dans `.trash`. `api.files.create().save()` vers un ordinateur est refusé (`storage_is_local`).
|
|
277
|
-
|
|
278
|
-
### Stockages connectés
|
|
279
|
-
|
|
280
|
-
```js
|
|
281
|
-
const mongo = await api.storage.connect({ label: "Ma base", type: "database", provider: "mongodb", endpoint: { credentials: { uri: "mongodb+srv://…/madb" } } })
|
|
282
|
-
|
|
283
|
-
await mongo.run({ action: "collections" }) // [{ name, count }]
|
|
284
|
-
await mongo.run({ action: "find", collection: "users", filter: {}, options: { limit: 20, skip: 0 } })
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
`connect()` enregistre la connexion (secrets chiffrés côté serveur) **sans la tester** : une URI fausse n'échoue
|
|
288
|
-
qu'au premier `run()`. Un ordinateur, lui, devient un stockage au premier appel du SDK sur cette machine.
|
|
289
|
-
|
|
290
|
-
Mettez l'URI dans `credentials`, qui est chiffré au repos — **pas** dans `endpoint.uri`, gardé en clair.
|
|
291
|
-
Depuis P78, `endpoint` n'est de toute façon **jamais rendu** : ni par `connect()`, ni par `get()`, ni par
|
|
292
|
-
`list()`. Le serveur s'en sert pour se connecter ; vous, vous l'avez fourni.
|
|
293
|
-
|
|
294
|
-
Pour MongoDB, la base est lue **dans le chemin de l'URI** (`…mongodb.net/madb`) ; sans elle, le serveur utilise
|
|
295
|
-
`iagenify_db`, qui paraîtra vide.
|
|
296
|
-
|
|
297
|
-
```js
|
|
298
|
-
await api.storage.remove(storage.id) // { ok: true } — le stockage par défaut aussi : son drapeau passe au suivant
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
Pour que l'agent lise la base, passez-la en `storages` avec l'outil `api.tools.queryStorage` (lecture seule) :
|
|
302
|
-
|
|
303
|
-
```js
|
|
304
|
-
api.agents.create({ model: { main }, storages: [mongo], tools: { query_storage: api.tools.queryStorage } })
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
### `api.workflows` — workflows exécutés par n8n (0.2.0)
|
|
308
|
-
|
|
309
|
-
Un workflow est un graphe sans cycle ; n8n route les branches, synchronise les chemins parallèles,
|
|
310
|
-
attend les validations humaines et planifie. L'API IaGenify exécute chaque primitive avec les crédits du compte.
|
|
311
|
-
|
|
312
|
-
```js
|
|
313
|
-
const workflow = await api.workflows.create({
|
|
314
|
-
name: "veille",
|
|
315
|
-
trigger: { type: "manual" }, // ou { type: "cron", cron: "0 6 * * *", timezone: "UTC" } | { type: "webhook" }
|
|
316
|
-
steps: [
|
|
317
|
-
{ id: "search", type: "tools.search", config: { query: "{{input.subject}}", engines: ["google"] } },
|
|
318
|
-
{ id: "pick", type: "human", config: { title: "Choisir une source" } },
|
|
319
|
-
{ id: "summary", type: "model.generate", config: {
|
|
320
|
-
model: "gemini-3.5-flash", settings: { temperature: 0.2 },
|
|
321
|
-
inputs: [{ type: "text", content: "Résume {{steps.pick.output.url}}" }] } },
|
|
322
|
-
],
|
|
323
|
-
edges: [
|
|
324
|
-
{ from: "__trigger", to: "search", branch: "next" },
|
|
325
|
-
{ from: "search", to: "pick", branch: "next" },
|
|
326
|
-
{ from: "pick", to: "summary", branch: "next" },
|
|
327
|
-
],
|
|
328
|
-
})
|
|
329
|
-
|
|
330
|
-
const run = await workflow.run({ input: { subject: "Next.js 16" } })
|
|
331
|
-
await run.wait() // s'arrête sur "waiting" ou sur la fin
|
|
332
|
-
await run.resume("pick", { url: "https://nextjs.org/blog/next-16" })
|
|
333
|
-
await run.wait({ until: ["succeeded", "failed", "cancelled"] })
|
|
334
|
-
console.log(run.data.steps.at(-1).output.outputs[0].content)
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
| Type d'étape | `config` | `output` (identique à l'appel SDK équivalent) |
|
|
338
|
-
|---|---|---|
|
|
339
|
-
| `model.generate` | `{ model, settings?, schema?, inputs, outputs? }` | retour de `assistant.generate()` |
|
|
340
|
-
| `agent.run` | `{ model, tools?, maxSteps?, budget?, inputs, outputs? }` | retour de `agent.run()` |
|
|
341
|
-
| `tools.search` | options de `api.tools.search()` | retour de `api.tools.search()` |
|
|
342
|
-
| `tools.fetch` | options de `api.tools.fetch()` | retour de `api.tools.fetch()` |
|
|
343
|
-
| `http` | `{ url, method?, headers?, body?, timeoutMs? }` | `{ status, body }` |
|
|
344
|
-
| `human` | `{ title? }` | les données passées à `run.resume()` |
|
|
345
|
-
| `condition` | `{ left, operator, right? }` | `{ result, left, operator, right? }` ; sorties `true`/`false` |
|
|
346
|
-
| `switch` | `{ value, cases: [{ key, operator, value }] }` | `{ branch, value }` ; une sortie par clé + `default` |
|
|
347
|
-
| `merge` | `{ mode: "append" }` | `{ merged: true }` après au moins deux entrées parallèles |
|
|
348
|
-
| `storage.query` | `{ storage: "<id>", ...options de storage.run() }` (MongoDB, D1, R2/S3) | `{ storage, provider, result }` |
|
|
349
|
-
| `file.save` | `{ storage: "<id R2/S3>", path, content \| contentBase64, contentType? }` | `{ storage, provider, key, size, contentType }` |
|
|
350
|
-
| `tools.convert` | `{ from, to, url \| content \| base64 }` — 1 crédit, rendu en cas d'échec | retour de `api.tools.convert()` |
|
|
351
|
-
| `memory` | `{ action: "read" \| "write" \| "delete", name?, content?, description? }` | la note (`found`, `content`), la liste, ou `{ deleted }` |
|
|
352
|
-
|
|
353
|
-
- `agent.run` accepte aussi `skills: [{ name, content }]` et `subagent: { name, content }` : leur texte est donné à l'agent avant la tâche, jamais lu comme un gabarit. Un run tourne sur le serveur : il n'atteint pas l'ordinateur (d'où `file.save` limité à R2/S3).
|
|
354
|
-
|
|
355
|
-
- `model` : un nom de modèle, ou `{ main, image, … }` pour un agent ; la session vit le temps du run.
|
|
356
|
-
- `tools` : même syntaxe qu'`agents.create` (`{ run: api.tools.search, options }`).
|
|
357
|
-
- Gabarits : `{{input.x}}`, `{{steps.<id>.output.x}}` (index compris : `candidates.0.lead.title`). Un gabarit seul rend la valeur brute ; une valeur absente devient `""` et s'ajoute à `run.data.steps[i].warnings`.
|
|
358
|
-
- Connexions : `{ from, to, branch }`. Les étapes ordinaires peuvent avoir plusieurs sorties `next` parallèles ; `condition` utilise `true`/`false`, `switch` ses clés et `default`, `merge` attend au moins deux entrées.
|
|
359
|
-
- `run.data` : `{ id, workflowId, status, input, steps: [{ id, type, status, output, credits, startedAt, endedAt, error, warnings }], waiting: { stepId, title, since } | null, credits, startedAt, endedAt }` — `status` vaut `running`, `waiting`, `succeeded`, `failed` ou `cancelled`.
|
|
360
|
-
- Méthodes : `api.workflows.list()`, `api.workflows.get(id)`, `workflow.run()`, `workflow.runs()`, `workflow.update()`, `workflow.destroy()`, `run.refresh()`, `run.wait()`, `run.resume()`, `run.cancel()`, `run.retry(stepId?)`.
|
|
361
|
-
- `run.retry(stepId?)` relance un run `failed`, `cancelled` ou `waiting` à partir de `stepId` (par défaut l'étape en échec) : les étapes précédentes sont gardées, les essais remplacés restent dans `run.data.steps[i].attempts`.
|
|
362
|
-
- `workflow.runStep(stepId, { fromRun?, input?, steps? })` exécute une seule étape (comme « Execute step » dans n8n), avec pour contexte un run existant et/ou des sorties fournies à la main ; rend `{ id, type, status, output, credits, startedAt, endedAt, error, warnings }` sans modifier aucun run. Une étape `human` renvoie `step_not_executable`.
|
|
363
|
-
- Erreurs : `invalid_workflow` (définition refusée), `workflow_not_found`, `run_not_found`, `run_not_waiting`, `run_not_retryable`, `step_not_found`, `step_not_executable`, `n8n_unreachable` (n8n arrêté ou `N8N_API_KEY` absente). Un refus de n8n lui-même renvoie `internal_error`.
|
|
364
|
-
|
|
365
|
-
### `api.keys.list()`, `api.keys.revoke(id)`
|
|
366
|
-
|
|
367
|
-
Lire et révoquer, jamais créer (P77). `list()` rend `{ ok, keys }` — `id`, `name`, `prefix`, `scopes`,
|
|
368
|
-
`lastUsedAt`, `expiresAt`, `isActive`, `createdAt`, et aucun secret. `revoke(id)` rend `{ ok: true }`,
|
|
369
|
-
ou `404 not_found` si aucune clé active ne porte cet id. Une clé se crée depuis le compte : un
|
|
370
|
-
programme qui en fabrique transforme une clé fuitée en autant de clés qu'en veut celui qui la tient,
|
|
371
|
-
et celles-là survivent à la révocation de la première.
|
|
372
|
-
|
|
373
|
-
### `api.auth.logout()`, `api.auth.revokeSession(id)`, `api.auth.updateProfile(updates)`
|
|
374
|
-
|
|
375
|
-
## Retour de `assistant.generate()`
|
|
376
|
-
|
|
377
|
-
```js
|
|
378
|
-
{
|
|
379
|
-
outputs: [{ type, content, mime?, description? }],
|
|
380
|
-
usage: { credits, inputTokens?, outputTokens? },
|
|
381
|
-
model: "...",
|
|
382
|
-
service: "..."
|
|
383
|
-
}
|
|
384
|
-
```
|
|
385
|
-
|
|
386
|
-
- `content` : string (texte), base64 (binaire), ou array (embedding)
|
|
387
|
-
- `mime` : présent pour image, audio, vidéo
|
|
388
|
-
|
|
389
|
-
## Configuration
|
|
390
|
-
|
|
391
|
-
Les clés API sont échangées automatiquement contre des JWT via `POST /api/auth/sessions/exchange`. Les sessions sont persistées dans :
|
|
392
|
-
- **Node** : fichier `~/.iagenify/session`
|
|
393
|
-
- **Browser** : `localStorage`
|
|
394
|
-
- **Worker** : mémoire
|
|
395
|
-
|
|
396
|
-
Le refresh token prolonge la session automatiquement.
|
|
187
|
+
|
|
188
|
+
```js
|
|
189
|
+
const main = await api.models.create({ model: "gemini-3.5-flash", memory: false });
|
|
190
|
+
const image = await api.models.create({ model: "gemini-2.5-flash-image", memory: false });
|
|
191
|
+
|
|
192
|
+
const agent = api.agents.create({
|
|
193
|
+
model: { main, image },
|
|
194
|
+
tools: {
|
|
195
|
+
search: api.tools.search,
|
|
196
|
+
openPage: api.tools.fetch,
|
|
197
|
+
createImage: api.tools.image,
|
|
198
|
+
},
|
|
199
|
+
maxSteps: 8,
|
|
200
|
+
budget: 100,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const result = await agent.run({
|
|
204
|
+
inputs: [{ type: "text", content: "Cherche une source puis illustre la réponse." }],
|
|
205
|
+
onStep: (step) => console.log(step),
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
await agent.destroy();
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
La clé de chaque outil est le nom présenté au modèle. Les modèles et stockages
|
|
212
|
+
doivent être des objets déjà obtenus auprès du SDK. `run()` conserve un historique
|
|
213
|
+
léger entre ses appels, diffuse les étapes et accepte un `AbortSignal`. `stop()`
|
|
214
|
+
demande un arrêt coopératif du run courant.
|
|
215
|
+
|
|
216
|
+
## API Reference
|
|
217
|
+
|
|
218
|
+
### `new IaGenify({ apiKey, baseUrl?, storage?, sessionPath?, appName? })`
|
|
219
|
+
|
|
220
|
+
| Option | Default | Description |
|
|
221
|
+
|---|---|---|
|
|
222
|
+
| `apiKey` | — | Clé API (requise si pas de session) |
|
|
223
|
+
| `baseUrl` | `http://localhost:3000` | URL du serveur |
|
|
224
|
+
| `storage` | auto (fs/localStorage/memory) | Stockage session personnalisé |
|
|
225
|
+
| `sessionPath` | `~/.iagenify/session` | Chemin fichier session (Node) |
|
|
226
|
+
| `appName` | — | Nom de l'application |
|
|
227
|
+
|
|
228
|
+
### `api.models.create({ model, settings?, schema?, memory? })` → `AssistantSession`
|
|
229
|
+
|
|
230
|
+
| Champ | Default | Description |
|
|
231
|
+
|---|---|---|
|
|
232
|
+
| `model` | — | Nom du modèle (requis) |
|
|
233
|
+
| `settings` | `{}` | `{ role?, instructions?, negativePrompt?, temperature?, maxOutputTokens? }` — `temperature: 0` est appliqué (sortie déterministe) ; `maxOutputTokens` vaut 8192 par défaut |
|
|
234
|
+
| `schema` | `null` | JSON Schema pour sortie structurée |
|
|
235
|
+
| `memory` | `true` | Conservation du contexte entre appels |
|
|
236
|
+
|
|
237
|
+
### `assistant.generate({ inputs, outputs? })` → `{ outputs, usage, ... }`
|
|
238
|
+
|
|
239
|
+
- `inputs` : tableau de `{ type, content?, url?, mime?, path? }` (requis)
|
|
240
|
+
- `outputs` : tableau de `{ type, description?, schema? }` (optionnel, format imposé par le modèle)
|
|
241
|
+
|
|
242
|
+
Types supportés (`inputs`) : `text`, `image`, `video`, `audio`, `speech`, `passages`
|
|
243
|
+
|
|
244
|
+
### `assistant.data` → `{ id, model, settings, schema, memory, createdAt }`
|
|
245
|
+
|
|
246
|
+
### `assistant.getHistory()` → messages
|
|
247
|
+
|
|
248
|
+
### `assistant.destroy()` → suppression
|
|
249
|
+
|
|
250
|
+
### `api.getUser()` → `{ id, email, credits, pack }`
|
|
251
|
+
|
|
252
|
+
### `api.agents.create({ model, storages?, tools?, outputs?, maxSteps?, budget? })` → `Agent`
|
|
253
|
+
|
|
254
|
+
### `agent.run({ inputs, outputs?, history?, onStep?, signal? })` → `{ text, outputs, steps, artifacts, usage, stopReason }`
|
|
255
|
+
|
|
256
|
+
Chaque étape d'outil de `steps` (et chaque événement `onStep`) porte un `meta`
|
|
257
|
+
qui décrit ce que l'outil a réellement fait :
|
|
258
|
+
|
|
259
|
+
```js
|
|
260
|
+
// search
|
|
261
|
+
{ index: 0, kind: "tool", tool: "search", input, reasoning, summary: "5 résultat(s)", error: "", credits, durationMs,
|
|
262
|
+
meta: { enginesUsed: ["google"], cached: false, results: [{ title, url }] } }
|
|
263
|
+
// fetch
|
|
264
|
+
{ index: 1, kind: "tool", tool: "fetch", input, ..., meta: { url, title } }
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### `api.tools.search({ query, engines?, maxResults?, recencyDays?, language?, region?, safeSearch? })`
|
|
268
|
+
|
|
269
|
+
```js
|
|
270
|
+
const r = await api.tools.search({ query: "Next.js 16 release notes", engines: ["google"], maxResults: 8, recencyDays: 7 })
|
|
271
|
+
// { ok, query, results: [{ title, url, snippet, engine, engineKey, score, publishedDate? }],
|
|
272
|
+
// enginesUsed, engineErrors, cached, creditsUsed, timing: { durationMs } }
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
| Moteur | Par défaut | Coût |
|
|
276
|
+
|---|---|---|
|
|
277
|
+
| `searxng`, `wiki`, `stackex`, `arxiv` | oui | 1 crédit par recherche |
|
|
278
|
+
| `hackernews`, `forem` | non | inclus dans le crédit de base |
|
|
279
|
+
| `google` | non | 1 + 4 crédits (recherche Google via Vertex) |
|
|
280
|
+
|
|
281
|
+
`engines: ["all"]` interroge tous les moteurs, `google` compris. Une recherche
|
|
282
|
+
sans résultat est remboursée, et un moteur payant en échec n'est pas facturé.
|
|
283
|
+
Dans un agent, passez les moteurs par `options` :
|
|
284
|
+
`tools: { search: { run: api.tools.search, options: { engines: ["google"], maxResults: 8 } } }`.
|
|
285
|
+
|
|
286
|
+
### Fichiers de l'ordinateur (`~/.iagenify/files`)
|
|
287
|
+
|
|
288
|
+
Le stockage d'un ordinateur est gratuit et local : ses fichiers ne quittent jamais la machine.
|
|
289
|
+
|
|
290
|
+
```js
|
|
291
|
+
const pc = await api.storage.get()
|
|
292
|
+
await pc.files.write("Launch plan/brief.md", "# Brief")
|
|
293
|
+
await pc.files.list("Launch plan") // [{ name, path, type: "file" | "folder", size, mimeType, modifiedAt }]
|
|
294
|
+
await pc.files.read("Launch plan/brief.md")
|
|
295
|
+
await pc.files.mkdir("Archive") ; await pc.files.move("Launch plan/brief.md", "Archive/brief.md") ; await pc.files.remove("Archive")
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Un agent qui reçoit ce stockage en `storages` lit ces fichiers avec `list_documents` / `read_document`, et les
|
|
299
|
+
écrit avec `write_document`, `create_folder`, `move_document`, `delete_document` : le serveur demande l'opération au
|
|
300
|
+
SDK de la machine, qui la fait sur le disque. Une mise à jour garde l'ancienne version dans `.versions`, une
|
|
301
|
+
suppression va dans `.trash`. `api.files.create().save()` vers un ordinateur est refusé (`storage_is_local`).
|
|
302
|
+
|
|
303
|
+
### Stockages connectés
|
|
304
|
+
|
|
305
|
+
```js
|
|
306
|
+
const mongo = await api.storage.connect({ label: "Ma base", type: "database", provider: "mongodb", endpoint: { credentials: { uri: "mongodb+srv://…/madb" } } })
|
|
307
|
+
|
|
308
|
+
await mongo.run({ action: "collections" }) // [{ name, count }]
|
|
309
|
+
await mongo.run({ action: "find", collection: "users", filter: {}, options: { limit: 20, skip: 0 } })
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
`connect()` enregistre la connexion (secrets chiffrés côté serveur) **sans la tester** : une URI fausse n'échoue
|
|
313
|
+
qu'au premier `run()`. Un ordinateur, lui, devient un stockage au premier appel du SDK sur cette machine.
|
|
314
|
+
|
|
315
|
+
Mettez l'URI dans `credentials`, qui est chiffré au repos — **pas** dans `endpoint.uri`, gardé en clair.
|
|
316
|
+
Depuis P78, `endpoint` n'est de toute façon **jamais rendu** : ni par `connect()`, ni par `get()`, ni par
|
|
317
|
+
`list()`. Le serveur s'en sert pour se connecter ; vous, vous l'avez fourni.
|
|
318
|
+
|
|
319
|
+
Pour MongoDB, la base est lue **dans le chemin de l'URI** (`…mongodb.net/madb`) ; sans elle, le serveur utilise
|
|
320
|
+
`iagenify_db`, qui paraîtra vide.
|
|
321
|
+
|
|
322
|
+
```js
|
|
323
|
+
await api.storage.remove(storage.id) // { ok: true } — le stockage par défaut aussi : son drapeau passe au suivant
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Pour que l'agent lise la base, passez-la en `storages` avec l'outil `api.tools.queryStorage` (lecture seule) :
|
|
327
|
+
|
|
328
|
+
```js
|
|
329
|
+
api.agents.create({ model: { main }, storages: [mongo], tools: { query_storage: api.tools.queryStorage } })
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### `api.workflows` — workflows exécutés par n8n (0.2.0)
|
|
333
|
+
|
|
334
|
+
Un workflow est un graphe sans cycle ; n8n route les branches, synchronise les chemins parallèles,
|
|
335
|
+
attend les validations humaines et planifie. L'API IaGenify exécute chaque primitive avec les crédits du compte.
|
|
336
|
+
|
|
337
|
+
```js
|
|
338
|
+
const workflow = await api.workflows.create({
|
|
339
|
+
name: "veille",
|
|
340
|
+
trigger: { type: "manual" }, // ou { type: "cron", cron: "0 6 * * *", timezone: "UTC" } | { type: "webhook" }
|
|
341
|
+
steps: [
|
|
342
|
+
{ id: "search", type: "tools.search", config: { query: "{{input.subject}}", engines: ["google"] } },
|
|
343
|
+
{ id: "pick", type: "human", config: { title: "Choisir une source" } },
|
|
344
|
+
{ id: "summary", type: "model.generate", config: {
|
|
345
|
+
model: "gemini-3.5-flash", settings: { temperature: 0.2 },
|
|
346
|
+
inputs: [{ type: "text", content: "Résume {{steps.pick.output.url}}" }] } },
|
|
347
|
+
],
|
|
348
|
+
edges: [
|
|
349
|
+
{ from: "__trigger", to: "search", branch: "next" },
|
|
350
|
+
{ from: "search", to: "pick", branch: "next" },
|
|
351
|
+
{ from: "pick", to: "summary", branch: "next" },
|
|
352
|
+
],
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
const run = await workflow.run({ input: { subject: "Next.js 16" } })
|
|
356
|
+
await run.wait() // s'arrête sur "waiting" ou sur la fin
|
|
357
|
+
await run.resume("pick", { url: "https://nextjs.org/blog/next-16" })
|
|
358
|
+
await run.wait({ until: ["succeeded", "failed", "cancelled"] })
|
|
359
|
+
console.log(run.data.steps.at(-1).output.outputs[0].content)
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
| Type d'étape | `config` | `output` (identique à l'appel SDK équivalent) |
|
|
363
|
+
|---|---|---|
|
|
364
|
+
| `model.generate` | `{ model, settings?, schema?, inputs, outputs? }` | retour de `assistant.generate()` |
|
|
365
|
+
| `agent.run` | `{ model, tools?, maxSteps?, budget?, inputs, outputs? }` | retour de `agent.run()` |
|
|
366
|
+
| `tools.search` | options de `api.tools.search()` | retour de `api.tools.search()` |
|
|
367
|
+
| `tools.fetch` | options de `api.tools.fetch()` | retour de `api.tools.fetch()` |
|
|
368
|
+
| `http` | `{ url, method?, headers?, body?, timeoutMs? }` | `{ status, body }` |
|
|
369
|
+
| `human` | `{ title? }` | les données passées à `run.resume()` |
|
|
370
|
+
| `condition` | `{ left, operator, right? }` | `{ result, left, operator, right? }` ; sorties `true`/`false` |
|
|
371
|
+
| `switch` | `{ value, cases: [{ key, operator, value }] }` | `{ branch, value }` ; une sortie par clé + `default` |
|
|
372
|
+
| `merge` | `{ mode: "append" }` | `{ merged: true }` après au moins deux entrées parallèles |
|
|
373
|
+
| `storage.query` | `{ storage: "<id>", ...options de storage.run() }` (MongoDB, D1, R2/S3) | `{ storage, provider, result }` |
|
|
374
|
+
| `file.save` | `{ storage: "<id R2/S3>", path, content \| contentBase64, contentType? }` | `{ storage, provider, key, size, contentType }` |
|
|
375
|
+
| `tools.convert` | `{ from, to, url \| content \| base64 }` — 1 crédit, rendu en cas d'échec | retour de `api.tools.convert()` |
|
|
376
|
+
| `memory` | `{ action: "read" \| "write" \| "delete", name?, content?, description? }` | la note (`found`, `content`), la liste, ou `{ deleted }` |
|
|
377
|
+
|
|
378
|
+
- `agent.run` accepte aussi `skills: [{ name, content }]` et `subagent: { name, content }` : leur texte est donné à l'agent avant la tâche, jamais lu comme un gabarit. Un run tourne sur le serveur : il n'atteint pas l'ordinateur (d'où `file.save` limité à R2/S3).
|
|
379
|
+
|
|
380
|
+
- `model` : un nom de modèle, ou `{ main, image, … }` pour un agent ; la session vit le temps du run.
|
|
381
|
+
- `tools` : même syntaxe qu'`agents.create` (`{ run: api.tools.search, options }`).
|
|
382
|
+
- Gabarits : `{{input.x}}`, `{{steps.<id>.output.x}}` (index compris : `candidates.0.lead.title`). Un gabarit seul rend la valeur brute ; une valeur absente devient `""` et s'ajoute à `run.data.steps[i].warnings`.
|
|
383
|
+
- Connexions : `{ from, to, branch }`. Les étapes ordinaires peuvent avoir plusieurs sorties `next` parallèles ; `condition` utilise `true`/`false`, `switch` ses clés et `default`, `merge` attend au moins deux entrées.
|
|
384
|
+
- `run.data` : `{ id, workflowId, status, input, steps: [{ id, type, status, output, credits, startedAt, endedAt, error, warnings }], waiting: { stepId, title, since } | null, credits, startedAt, endedAt }` — `status` vaut `running`, `waiting`, `succeeded`, `failed` ou `cancelled`.
|
|
385
|
+
- Méthodes : `api.workflows.list()`, `api.workflows.get(id)`, `workflow.run()`, `workflow.runs()`, `workflow.update()`, `workflow.destroy()`, `run.refresh()`, `run.wait()`, `run.resume()`, `run.cancel()`, `run.retry(stepId?)`.
|
|
386
|
+
- `run.retry(stepId?)` relance un run `failed`, `cancelled` ou `waiting` à partir de `stepId` (par défaut l'étape en échec) : les étapes précédentes sont gardées, les essais remplacés restent dans `run.data.steps[i].attempts`.
|
|
387
|
+
- `workflow.runStep(stepId, { fromRun?, input?, steps? })` exécute une seule étape (comme « Execute step » dans n8n), avec pour contexte un run existant et/ou des sorties fournies à la main ; rend `{ id, type, status, output, credits, startedAt, endedAt, error, warnings }` sans modifier aucun run. Une étape `human` renvoie `step_not_executable`.
|
|
388
|
+
- Erreurs : `invalid_workflow` (définition refusée), `workflow_not_found`, `run_not_found`, `run_not_waiting`, `run_not_retryable`, `step_not_found`, `step_not_executable`, `n8n_unreachable` (n8n arrêté ou `N8N_API_KEY` absente). Un refus de n8n lui-même renvoie `internal_error`.
|
|
389
|
+
|
|
390
|
+
### `api.keys.list()`, `api.keys.revoke(id)`
|
|
391
|
+
|
|
392
|
+
Lire et révoquer, jamais créer (P77). `list()` rend `{ ok, keys }` — `id`, `name`, `prefix`, `scopes`,
|
|
393
|
+
`lastUsedAt`, `expiresAt`, `isActive`, `createdAt`, et aucun secret. `revoke(id)` rend `{ ok: true }`,
|
|
394
|
+
ou `404 not_found` si aucune clé active ne porte cet id. Une clé se crée depuis le compte : un
|
|
395
|
+
programme qui en fabrique transforme une clé fuitée en autant de clés qu'en veut celui qui la tient,
|
|
396
|
+
et celles-là survivent à la révocation de la première.
|
|
397
|
+
|
|
398
|
+
### `api.auth.logout()`, `api.auth.revokeSession(id)`, `api.auth.updateProfile(updates)`
|
|
399
|
+
|
|
400
|
+
## Retour de `assistant.generate()`
|
|
401
|
+
|
|
402
|
+
```js
|
|
403
|
+
{
|
|
404
|
+
outputs: [{ type, content, mime?, description? }],
|
|
405
|
+
usage: { credits, inputTokens?, outputTokens? },
|
|
406
|
+
model: "...",
|
|
407
|
+
service: "..."
|
|
408
|
+
}
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
- `content` : string (texte), base64 (binaire), ou array (embedding)
|
|
412
|
+
- `mime` : présent pour image, audio, vidéo
|
|
413
|
+
|
|
414
|
+
## Configuration
|
|
415
|
+
|
|
416
|
+
Les clés API sont échangées automatiquement contre des JWT via `POST /api/auth/sessions/exchange`. Les sessions sont persistées dans :
|
|
417
|
+
- **Node** : fichier `~/.iagenify/session`
|
|
418
|
+
- **Browser** : `localStorage`
|
|
419
|
+
- **Worker** : mémoire
|
|
420
|
+
|
|
421
|
+
Le refresh token prolonge la session automatiquement.
|
package/dist/index.cjs
CHANGED
|
@@ -3403,25 +3403,30 @@ function sendMailTool() {
|
|
|
3403
3403
|
return {
|
|
3404
3404
|
// Catégorie `send` (P39) : demandée à chaque envoi, même en Full access, sans « toujours ».
|
|
3405
3405
|
category: "send",
|
|
3406
|
-
|
|
3406
|
+
// P82 : `html` pour un message mis en forme, `attach` joint vraiment les fichiers (25 Mo au total). Avant,
|
|
3407
|
+
// `attach` lisait les fichiers puis les perdait — la route d'envoi n'en prenait pas — et l'agent disait « envoyé ».
|
|
3408
|
+
description: "Send a message FROM one of the account's own addresses, signed with their domain's key. The account must own a mailbox: there is no other way to send, so if it has none, say so and point at Mail rather than improvising. reply_to_message answers one: the subject, recipient and thread are kept and the original quoted. html sends a formatted message (inline styles only, tables for layout: mail clients ignore stylesheets); body is then the plain-text fallback. attach joins workspace files, 25 MB in all, executables refused. The user approves every send, in every mode. Accepted by the relay is not delivered \u2014 never tell them it arrived.",
|
|
3407
3409
|
parameters: {
|
|
3408
3410
|
box: { type: "string", description: "Which of its addresses writes; optional when it owns one" },
|
|
3409
3411
|
to: { type: "string", required: true, description: "Comma-separated, at most 5" },
|
|
3410
3412
|
cc: { type: "string", description: "Comma-separated" },
|
|
3413
|
+
bcc: { type: "string", description: "Comma-separated, hidden from the other recipients" },
|
|
3411
3414
|
subject: { type: "string", description: "Required unless replying" },
|
|
3412
|
-
body: { type: "string",
|
|
3415
|
+
body: { type: "string", description: "Plain text; blank lines separate paragraphs. Required unless html is given" },
|
|
3416
|
+
html: { type: "string", description: "Formatted message: inline styles, no script, no external stylesheet" },
|
|
3413
3417
|
reply_to_message: { type: "string", description: "Id of the message being answered" },
|
|
3414
|
-
attach: { type: "array", items: { type: "string" }, description: "Workspace files" },
|
|
3418
|
+
attach: { type: "array", items: { type: "string" }, description: "Workspace files to attach" },
|
|
3415
3419
|
signature: { type: "boolean", description: "false sends without the mailbox signature" }
|
|
3416
3420
|
},
|
|
3417
|
-
check({ to, subject, reply_to_message, body } = {}) {
|
|
3421
|
+
check({ to, cc, bcc, subject, reply_to_message, body, html } = {}) {
|
|
3418
3422
|
const recipients = addresses(to);
|
|
3419
3423
|
if (!recipients.length) fail4('"to" is required: at least one recipient.');
|
|
3420
3424
|
if (recipients.length > 5) fail4(`At most 5 recipients at a time; you gave ${recipients.length}.`);
|
|
3421
|
-
const bad = recipients.find((a) => !/^[^@\s]+@[^@\s.]+\.[^@\s]+$/.test(a));
|
|
3425
|
+
const bad = [...recipients, ...addresses(cc), ...addresses(bcc)].find((a) => !/^[^@\s]+@[^@\s.]+\.[^@\s]+$/.test(a));
|
|
3422
3426
|
if (bad) fail4(`"${bad}" is not an email address.`);
|
|
3423
3427
|
if (!text(subject) && !text(reply_to_message)) fail4('"subject" is required (or give reply_to_message to answer a message).');
|
|
3424
|
-
if (!text(body)) fail4('"body" is required: write the message in full, as the user would.');
|
|
3428
|
+
if (!text(body) && !text(html)) fail4('"body" or "html" is required: write the message in full, as the user would.');
|
|
3429
|
+
if (/<script\b|\son\w+\s*=|javascript:/i.test(String(html || ""))) fail4('"html" must not carry script, event handlers or javascript: links \u2014 mail clients strip them and spam filters punish them.');
|
|
3425
3430
|
},
|
|
3426
3431
|
async run(args, { api, files }) {
|
|
3427
3432
|
const box = await findBox(api, args.box);
|
|
@@ -3440,26 +3445,30 @@ ${quoted}`;
|
|
|
3440
3445
|
const attachments = [];
|
|
3441
3446
|
for (const path of Array.isArray(args.attach) ? args.attach : addresses(args.attach)) {
|
|
3442
3447
|
const file = await files.read(String(path));
|
|
3443
|
-
attachments.push({
|
|
3448
|
+
attachments.push({ filename: String(path).split("/").pop(), content: file.content, ...file.mimeType ? { contentType: file.mimeType } : {} });
|
|
3444
3449
|
}
|
|
3445
3450
|
const sent = await box.send({
|
|
3446
3451
|
to,
|
|
3447
3452
|
cc: addresses(args.cc),
|
|
3453
|
+
bcc: addresses(args.bcc),
|
|
3448
3454
|
subject,
|
|
3449
3455
|
text: body,
|
|
3456
|
+
...text(args.html) ? { html: text(args.html) } : {},
|
|
3450
3457
|
...attachments.length ? { attachments } : {},
|
|
3451
3458
|
...args.signature === false ? { signature: false } : {}
|
|
3452
3459
|
});
|
|
3460
|
+
const joined = sent.attachments || [];
|
|
3453
3461
|
const relay = sent.relay || {};
|
|
3454
3462
|
return {
|
|
3455
3463
|
output: [
|
|
3456
|
-
`Sent from ${relay.from || box.address} to ${to.join(", ")} \u2014 "${subject}" (${sent.creditsUsed ?? 1} credit).`,
|
|
3464
|
+
`Sent from ${relay.from || box.address} to ${to.join(", ")} \u2014 "${subject}" (${sent.credits ?? sent.creditsUsed ?? 1} credit).`,
|
|
3465
|
+
joined.length ? `Attached: ${joined.map((a) => `${a.filename} (${formatBytes(a.size || 0)})`).join(", ")}.` : "",
|
|
3457
3466
|
relay.name ? `Relay: ${relay.name}${relay.aligned ? ", aligned (the signature is the account's own domain)" : ", NOT aligned \u2014 the recipient sees the relay's address and it may be filtered as spam"}.` : "",
|
|
3458
3467
|
relay.warning || "",
|
|
3459
3468
|
"Accepted by the relay is not delivered: it hands back as soon as the message is queued, and what the recipient's provider then does with it is not reported to us."
|
|
3460
3469
|
].filter(Boolean).join("\n"),
|
|
3461
3470
|
summary: `Mail to ${to[0]}${to.length > 1 ? ` +${to.length - 1}` : ""}`,
|
|
3462
|
-
meta: { box: box.id, to, subject, relay: relay.name || null, aligned: relay.aligned === true, credits: sent.creditsUsed ?? 1 }
|
|
3471
|
+
meta: { box: box.id, to, subject, relay: relay.name || null, aligned: relay.aligned === true, credits: sent.credits ?? sent.creditsUsed ?? 1, attachments: joined.length, html: Boolean(text(args.html)) }
|
|
3463
3472
|
};
|
|
3464
3473
|
}
|
|
3465
3474
|
};
|
|
@@ -6222,8 +6231,10 @@ async function sha256(content) {
|
|
|
6222
6231
|
var signature = (item) => `${item.size ?? 0}:${item.modifiedAt || ""}`;
|
|
6223
6232
|
var blobPath = (hash) => `${CHECKPOINT_DIR}/objects/${hash.slice(0, 2)}/${hash.slice(2)}`;
|
|
6224
6233
|
var missing = (err) => err?.code === "path_not_found" || err?.status === 404;
|
|
6225
|
-
function createCheckpoints({ files, sessionId, keep = KEEP_CHECKPOINTS }) {
|
|
6234
|
+
function createCheckpoints({ files, sessionId, keep = KEEP_CHECKPOINTS, excludePaths = [] }) {
|
|
6226
6235
|
const folder = `${CHECKPOINT_DIR}/${sessionId}`;
|
|
6236
|
+
const excluded = excludePaths.map((path) => String(path || "").replace(/\\/g, "/").replace(/^\/+|\/+$/g, ""));
|
|
6237
|
+
const excludedFromSnapshot = (path) => isOurs(path) || excluded.some((entry) => path === entry || path.startsWith(`${entry}/`));
|
|
6227
6238
|
async function scan() {
|
|
6228
6239
|
const found = [];
|
|
6229
6240
|
const heavy = [];
|
|
@@ -6239,7 +6250,7 @@ function createCheckpoints({ files, sessionId, keep = KEEP_CHECKPOINTS }) {
|
|
|
6239
6250
|
}
|
|
6240
6251
|
for (const item of items || []) {
|
|
6241
6252
|
const path = String(item.path || "").replace(/\\/g, "/").replace(/\/$/, "");
|
|
6242
|
-
if (!path ||
|
|
6253
|
+
if (!path || excludedFromSnapshot(path)) continue;
|
|
6243
6254
|
if (item.type === "folder") {
|
|
6244
6255
|
if (HEAVY_FOLDERS.has(item.name)) {
|
|
6245
6256
|
heavy.push(path);
|
|
@@ -6630,7 +6641,7 @@ function createJournal(agent2) {
|
|
|
6630
6641
|
}
|
|
6631
6642
|
var CLEAR_RESULTS_ABOVE = 4e4;
|
|
6632
6643
|
var DEFAULT_CONTEXT_TOKENS = 2e5;
|
|
6633
|
-
var catalogues = /* @__PURE__ */ new
|
|
6644
|
+
var catalogues = /* @__PURE__ */ new Map();
|
|
6634
6645
|
var KEEP_RESULTS_FOR_TURNS = 3;
|
|
6635
6646
|
var MIN_RESULT_TO_CLEAR = 400;
|
|
6636
6647
|
var SUBAGENT_MAX_STEPS = 40;
|
|
@@ -6864,10 +6875,11 @@ var LocalAgent = class _LocalAgent {
|
|
|
6864
6875
|
if (typeof this.api.catalogue !== "function" || !this.model) return;
|
|
6865
6876
|
let entry = null;
|
|
6866
6877
|
try {
|
|
6867
|
-
|
|
6878
|
+
const key = this.api.baseUrl || this.api;
|
|
6879
|
+
let cached = catalogues.get(key);
|
|
6868
6880
|
if (!cached || Date.now() - cached.at > 6e5) {
|
|
6869
6881
|
cached = { at: Date.now(), prices: await this.api.catalogue() };
|
|
6870
|
-
catalogues.set(
|
|
6882
|
+
catalogues.set(key, cached);
|
|
6871
6883
|
}
|
|
6872
6884
|
entry = cached.prices.find((p) => p.model === this.model && p.contextWindow);
|
|
6873
6885
|
} catch {
|
|
@@ -7508,7 +7520,10 @@ ${header.summary.text}` }, { role: "assistant", content: "Understood. Continuing
|
|
|
7508
7520
|
/** Le magasin de points de cette session, créé au premier besoin. */
|
|
7509
7521
|
_checkpoints() {
|
|
7510
7522
|
if (!this.checkpointsOption || !this.memory || this.role) return null;
|
|
7511
|
-
if (!this.checkpointStore)
|
|
7523
|
+
if (!this.checkpointStore) {
|
|
7524
|
+
const excludePaths = this.machine?.managedBy === "iagenify" && this.machine?.service === "object" ? ["Chats"] : [];
|
|
7525
|
+
this.checkpointStore = createCheckpoints({ files: this._files(), sessionId: this.id, excludePaths });
|
|
7526
|
+
}
|
|
7512
7527
|
return this.checkpointStore;
|
|
7513
7528
|
}
|
|
7514
7529
|
/** Enregistre l'espace de travail avant ce message. Un instantané impossible n'empêche jamais de répondre. */
|
|
@@ -7971,8 +7986,7 @@ ${summary.message.content}` }, { role: "assistant", content: "Understood. Contin
|
|
|
7971
7986
|
emit({ type: "rewound", ...rewound });
|
|
7972
7987
|
}
|
|
7973
7988
|
const root = await this._root();
|
|
7974
|
-
await this._loadLibrary();
|
|
7975
|
-
await this._loadMcp();
|
|
7989
|
+
await Promise.all([this._loadLibrary(), this._loadMcp()]);
|
|
7976
7990
|
const parsed = await this._parseInput(raw);
|
|
7977
7991
|
const restore = this._applyRunOptions(parsed.options);
|
|
7978
7992
|
try {
|
|
@@ -8006,8 +8020,7 @@ ${summary.message.content}` }, { role: "assistant", content: "Understood. Contin
|
|
|
8006
8020
|
emit({ type: "question_result", id, answer: answer ?? "" });
|
|
8007
8021
|
return answer;
|
|
8008
8022
|
} : null;
|
|
8009
|
-
this.storageContext = this.parent ? this.parent.storageContext : await this._loadStorageContext();
|
|
8010
|
-
this.memories = this.parent ? this.parent.memories : await this._loadMemories();
|
|
8023
|
+
[this.storageContext, this.memories] = this.parent ? [this.parent.storageContext, this.parent.memories] : await Promise.all([this._loadStorageContext(), this._loadMemories()]);
|
|
8011
8024
|
const context = { files: this._files(), shell: this.shell, terminals: this._terminals(), mode: () => this.mode, root, api: this.api, todos: this.todos, signal: this.controller.signal, askUser };
|
|
8012
8025
|
const usage = this.usage = { credits: 0, turns: 0, toolCalls: 0 };
|
|
8013
8026
|
let stopReason = "end_turn";
|
|
@@ -9092,6 +9105,49 @@ var ComputeResource = class {
|
|
|
9092
9105
|
};
|
|
9093
9106
|
|
|
9094
9107
|
// src/resources/mail.js
|
|
9108
|
+
function octetsEnBase64(octets) {
|
|
9109
|
+
if (typeof Buffer !== "undefined") return Buffer.from(octets.buffer, octets.byteOffset, octets.byteLength).toString("base64");
|
|
9110
|
+
let binaire = "";
|
|
9111
|
+
for (let i = 0; i < octets.length; i += 32768) binaire += String.fromCharCode(...octets.subarray(i, i + 32768));
|
|
9112
|
+
return btoa(binaire);
|
|
9113
|
+
}
|
|
9114
|
+
var nomDe = (chemin) => String(chemin).split(/[\\/]/).pop();
|
|
9115
|
+
async function encoderPiece(piece, index) {
|
|
9116
|
+
if (!piece || typeof piece !== "object") {
|
|
9117
|
+
throw new TypeError(`attachments[${index}] doit \xEAtre un objet { filename, content } ou { path }.`);
|
|
9118
|
+
}
|
|
9119
|
+
let { filename, content } = piece;
|
|
9120
|
+
if (content == null && piece.path) {
|
|
9121
|
+
if (typeof process === "undefined" || !process.versions?.node) {
|
|
9122
|
+
throw new TypeError(`attachments[${index}].path ne fonctionne que dans Node : passez content (octets ou Blob) ailleurs.`);
|
|
9123
|
+
}
|
|
9124
|
+
const { readFile } = await import("node:fs/promises");
|
|
9125
|
+
content = await readFile(piece.path);
|
|
9126
|
+
filename ??= nomDe(piece.path);
|
|
9127
|
+
}
|
|
9128
|
+
if (content == null) throw new TypeError(`attachments[${index}] n'a ni content ni path.`);
|
|
9129
|
+
let base64;
|
|
9130
|
+
if (typeof content === "string") {
|
|
9131
|
+
base64 = piece.encoding === "base64" ? content.replace(/\s+/g, "") : octetsEnBase64(new TextEncoder().encode(content));
|
|
9132
|
+
} else if (typeof Blob !== "undefined" && content instanceof Blob) {
|
|
9133
|
+
base64 = octetsEnBase64(new Uint8Array(await content.arrayBuffer()));
|
|
9134
|
+
filename ??= content.name;
|
|
9135
|
+
} else if (content instanceof ArrayBuffer) {
|
|
9136
|
+
base64 = octetsEnBase64(new Uint8Array(content));
|
|
9137
|
+
} else if (ArrayBuffer.isView(content)) {
|
|
9138
|
+
base64 = octetsEnBase64(new Uint8Array(content.buffer, content.byteOffset, content.byteLength));
|
|
9139
|
+
} else {
|
|
9140
|
+
throw new TypeError(`attachments[${index}].content doit \xEAtre un Buffer, un Uint8Array, un ArrayBuffer, un Blob ou une cha\xEEne.`);
|
|
9141
|
+
}
|
|
9142
|
+
const sortie = { filename: filename || `piece-${index + 1}`, content: base64 };
|
|
9143
|
+
if (piece.contentType) sortie.contentType = piece.contentType;
|
|
9144
|
+
if (piece.cid) sortie.cid = piece.cid;
|
|
9145
|
+
return sortie;
|
|
9146
|
+
}
|
|
9147
|
+
async function encodeAttachments(attachments) {
|
|
9148
|
+
if (!Array.isArray(attachments)) throw new TypeError("attachments doit \xEAtre une liste.");
|
|
9149
|
+
return Promise.all(attachments.map(encoderPiece));
|
|
9150
|
+
}
|
|
9095
9151
|
var Aliases = class {
|
|
9096
9152
|
constructor(client, mailbox) {
|
|
9097
9153
|
this.client = client;
|
|
@@ -9206,9 +9262,29 @@ var Mailbox = class {
|
|
|
9206
9262
|
* envoi-là. Quand elle demande l'image de la boîte, celle-ci voyage **dans** le message (`cid:`) : c'est la
|
|
9207
9263
|
* seule façon qu'un destinataire la voie, la pastille de son client étant dessinée depuis ses données à lui.
|
|
9208
9264
|
*/
|
|
9209
|
-
|
|
9265
|
+
/*
|
|
9266
|
+
* P82 (approuvé le 2026-11-18) — pièces jointes et Cci, dans la forme de nodemailer :
|
|
9267
|
+
*
|
|
9268
|
+
* await boite.send({
|
|
9269
|
+
* to: ["client@acme.com"], bcc: ["compta@moi.com"],
|
|
9270
|
+
* subject: "Votre facture",
|
|
9271
|
+
* html: '<h1>Merci</h1><img src="cid:logo">',
|
|
9272
|
+
* attachments: [
|
|
9273
|
+
* { filename: "facture.pdf", content: buffer, contentType: "application/pdf" },
|
|
9274
|
+
* { filename: "logo.png", content: png, cid: "logo" },
|
|
9275
|
+
* { filename: "devis.pdf", path: "./devis.pdf" }, // Node seulement
|
|
9276
|
+
* ],
|
|
9277
|
+
* });
|
|
9278
|
+
* // → { …, attachments: [{ filename, size, contentType, inline }] }
|
|
9279
|
+
*
|
|
9280
|
+
* `content` : Buffer, Uint8Array, ArrayBuffer, Blob, ou une chaîne — du texte UTF-8, sauf avec
|
|
9281
|
+
* `encoding: "base64"`, exactement comme nodemailer. 25 Mo au total ; les exécutables sont refusés.
|
|
9282
|
+
*/
|
|
9283
|
+
async send({ to = [], cc = [], bcc = [], subject = "", text: text2 = "", html = "", replyTo = null, signature: signature2, attachments } = {}) {
|
|
9210
9284
|
const corps = { to, cc, subject, text: text2, html, replyTo };
|
|
9285
|
+
if (bcc && (!Array.isArray(bcc) || bcc.length)) corps.bcc = bcc;
|
|
9211
9286
|
if (signature2 === false) corps.signature = false;
|
|
9287
|
+
if (attachments != null) corps.attachments = await encodeAttachments(attachments);
|
|
9212
9288
|
const res = await this.client.post(`/api/mail/${this.id}/send`, corps);
|
|
9213
9289
|
return res.sent;
|
|
9214
9290
|
}
|
package/dist/index.js
CHANGED
|
@@ -3345,25 +3345,30 @@ function sendMailTool() {
|
|
|
3345
3345
|
return {
|
|
3346
3346
|
// Catégorie `send` (P39) : demandée à chaque envoi, même en Full access, sans « toujours ».
|
|
3347
3347
|
category: "send",
|
|
3348
|
-
|
|
3348
|
+
// P82 : `html` pour un message mis en forme, `attach` joint vraiment les fichiers (25 Mo au total). Avant,
|
|
3349
|
+
// `attach` lisait les fichiers puis les perdait — la route d'envoi n'en prenait pas — et l'agent disait « envoyé ».
|
|
3350
|
+
description: "Send a message FROM one of the account's own addresses, signed with their domain's key. The account must own a mailbox: there is no other way to send, so if it has none, say so and point at Mail rather than improvising. reply_to_message answers one: the subject, recipient and thread are kept and the original quoted. html sends a formatted message (inline styles only, tables for layout: mail clients ignore stylesheets); body is then the plain-text fallback. attach joins workspace files, 25 MB in all, executables refused. The user approves every send, in every mode. Accepted by the relay is not delivered \u2014 never tell them it arrived.",
|
|
3349
3351
|
parameters: {
|
|
3350
3352
|
box: { type: "string", description: "Which of its addresses writes; optional when it owns one" },
|
|
3351
3353
|
to: { type: "string", required: true, description: "Comma-separated, at most 5" },
|
|
3352
3354
|
cc: { type: "string", description: "Comma-separated" },
|
|
3355
|
+
bcc: { type: "string", description: "Comma-separated, hidden from the other recipients" },
|
|
3353
3356
|
subject: { type: "string", description: "Required unless replying" },
|
|
3354
|
-
body: { type: "string",
|
|
3357
|
+
body: { type: "string", description: "Plain text; blank lines separate paragraphs. Required unless html is given" },
|
|
3358
|
+
html: { type: "string", description: "Formatted message: inline styles, no script, no external stylesheet" },
|
|
3355
3359
|
reply_to_message: { type: "string", description: "Id of the message being answered" },
|
|
3356
|
-
attach: { type: "array", items: { type: "string" }, description: "Workspace files" },
|
|
3360
|
+
attach: { type: "array", items: { type: "string" }, description: "Workspace files to attach" },
|
|
3357
3361
|
signature: { type: "boolean", description: "false sends without the mailbox signature" }
|
|
3358
3362
|
},
|
|
3359
|
-
check({ to, subject, reply_to_message, body } = {}) {
|
|
3363
|
+
check({ to, cc, bcc, subject, reply_to_message, body, html } = {}) {
|
|
3360
3364
|
const recipients = addresses(to);
|
|
3361
3365
|
if (!recipients.length) fail4('"to" is required: at least one recipient.');
|
|
3362
3366
|
if (recipients.length > 5) fail4(`At most 5 recipients at a time; you gave ${recipients.length}.`);
|
|
3363
|
-
const bad = recipients.find((a) => !/^[^@\s]+@[^@\s.]+\.[^@\s]+$/.test(a));
|
|
3367
|
+
const bad = [...recipients, ...addresses(cc), ...addresses(bcc)].find((a) => !/^[^@\s]+@[^@\s.]+\.[^@\s]+$/.test(a));
|
|
3364
3368
|
if (bad) fail4(`"${bad}" is not an email address.`);
|
|
3365
3369
|
if (!text(subject) && !text(reply_to_message)) fail4('"subject" is required (or give reply_to_message to answer a message).');
|
|
3366
|
-
if (!text(body)) fail4('"body" is required: write the message in full, as the user would.');
|
|
3370
|
+
if (!text(body) && !text(html)) fail4('"body" or "html" is required: write the message in full, as the user would.');
|
|
3371
|
+
if (/<script\b|\son\w+\s*=|javascript:/i.test(String(html || ""))) fail4('"html" must not carry script, event handlers or javascript: links \u2014 mail clients strip them and spam filters punish them.');
|
|
3367
3372
|
},
|
|
3368
3373
|
async run(args, { api, files }) {
|
|
3369
3374
|
const box = await findBox(api, args.box);
|
|
@@ -3382,26 +3387,30 @@ ${quoted}`;
|
|
|
3382
3387
|
const attachments = [];
|
|
3383
3388
|
for (const path of Array.isArray(args.attach) ? args.attach : addresses(args.attach)) {
|
|
3384
3389
|
const file = await files.read(String(path));
|
|
3385
|
-
attachments.push({
|
|
3390
|
+
attachments.push({ filename: String(path).split("/").pop(), content: file.content, ...file.mimeType ? { contentType: file.mimeType } : {} });
|
|
3386
3391
|
}
|
|
3387
3392
|
const sent = await box.send({
|
|
3388
3393
|
to,
|
|
3389
3394
|
cc: addresses(args.cc),
|
|
3395
|
+
bcc: addresses(args.bcc),
|
|
3390
3396
|
subject,
|
|
3391
3397
|
text: body,
|
|
3398
|
+
...text(args.html) ? { html: text(args.html) } : {},
|
|
3392
3399
|
...attachments.length ? { attachments } : {},
|
|
3393
3400
|
...args.signature === false ? { signature: false } : {}
|
|
3394
3401
|
});
|
|
3402
|
+
const joined = sent.attachments || [];
|
|
3395
3403
|
const relay = sent.relay || {};
|
|
3396
3404
|
return {
|
|
3397
3405
|
output: [
|
|
3398
|
-
`Sent from ${relay.from || box.address} to ${to.join(", ")} \u2014 "${subject}" (${sent.creditsUsed ?? 1} credit).`,
|
|
3406
|
+
`Sent from ${relay.from || box.address} to ${to.join(", ")} \u2014 "${subject}" (${sent.credits ?? sent.creditsUsed ?? 1} credit).`,
|
|
3407
|
+
joined.length ? `Attached: ${joined.map((a) => `${a.filename} (${formatBytes(a.size || 0)})`).join(", ")}.` : "",
|
|
3399
3408
|
relay.name ? `Relay: ${relay.name}${relay.aligned ? ", aligned (the signature is the account's own domain)" : ", NOT aligned \u2014 the recipient sees the relay's address and it may be filtered as spam"}.` : "",
|
|
3400
3409
|
relay.warning || "",
|
|
3401
3410
|
"Accepted by the relay is not delivered: it hands back as soon as the message is queued, and what the recipient's provider then does with it is not reported to us."
|
|
3402
3411
|
].filter(Boolean).join("\n"),
|
|
3403
3412
|
summary: `Mail to ${to[0]}${to.length > 1 ? ` +${to.length - 1}` : ""}`,
|
|
3404
|
-
meta: { box: box.id, to, subject, relay: relay.name || null, aligned: relay.aligned === true, credits: sent.creditsUsed ?? 1 }
|
|
3413
|
+
meta: { box: box.id, to, subject, relay: relay.name || null, aligned: relay.aligned === true, credits: sent.credits ?? sent.creditsUsed ?? 1, attachments: joined.length, html: Boolean(text(args.html)) }
|
|
3405
3414
|
};
|
|
3406
3415
|
}
|
|
3407
3416
|
};
|
|
@@ -6164,8 +6173,10 @@ async function sha256(content) {
|
|
|
6164
6173
|
var signature = (item) => `${item.size ?? 0}:${item.modifiedAt || ""}`;
|
|
6165
6174
|
var blobPath = (hash) => `${CHECKPOINT_DIR}/objects/${hash.slice(0, 2)}/${hash.slice(2)}`;
|
|
6166
6175
|
var missing = (err) => err?.code === "path_not_found" || err?.status === 404;
|
|
6167
|
-
function createCheckpoints({ files, sessionId, keep = KEEP_CHECKPOINTS }) {
|
|
6176
|
+
function createCheckpoints({ files, sessionId, keep = KEEP_CHECKPOINTS, excludePaths = [] }) {
|
|
6168
6177
|
const folder = `${CHECKPOINT_DIR}/${sessionId}`;
|
|
6178
|
+
const excluded = excludePaths.map((path) => String(path || "").replace(/\\/g, "/").replace(/^\/+|\/+$/g, ""));
|
|
6179
|
+
const excludedFromSnapshot = (path) => isOurs(path) || excluded.some((entry) => path === entry || path.startsWith(`${entry}/`));
|
|
6169
6180
|
async function scan() {
|
|
6170
6181
|
const found = [];
|
|
6171
6182
|
const heavy = [];
|
|
@@ -6181,7 +6192,7 @@ function createCheckpoints({ files, sessionId, keep = KEEP_CHECKPOINTS }) {
|
|
|
6181
6192
|
}
|
|
6182
6193
|
for (const item of items || []) {
|
|
6183
6194
|
const path = String(item.path || "").replace(/\\/g, "/").replace(/\/$/, "");
|
|
6184
|
-
if (!path ||
|
|
6195
|
+
if (!path || excludedFromSnapshot(path)) continue;
|
|
6185
6196
|
if (item.type === "folder") {
|
|
6186
6197
|
if (HEAVY_FOLDERS.has(item.name)) {
|
|
6187
6198
|
heavy.push(path);
|
|
@@ -6572,7 +6583,7 @@ function createJournal(agent2) {
|
|
|
6572
6583
|
}
|
|
6573
6584
|
var CLEAR_RESULTS_ABOVE = 4e4;
|
|
6574
6585
|
var DEFAULT_CONTEXT_TOKENS = 2e5;
|
|
6575
|
-
var catalogues = /* @__PURE__ */ new
|
|
6586
|
+
var catalogues = /* @__PURE__ */ new Map();
|
|
6576
6587
|
var KEEP_RESULTS_FOR_TURNS = 3;
|
|
6577
6588
|
var MIN_RESULT_TO_CLEAR = 400;
|
|
6578
6589
|
var SUBAGENT_MAX_STEPS = 40;
|
|
@@ -6806,10 +6817,11 @@ var LocalAgent = class _LocalAgent {
|
|
|
6806
6817
|
if (typeof this.api.catalogue !== "function" || !this.model) return;
|
|
6807
6818
|
let entry = null;
|
|
6808
6819
|
try {
|
|
6809
|
-
|
|
6820
|
+
const key = this.api.baseUrl || this.api;
|
|
6821
|
+
let cached = catalogues.get(key);
|
|
6810
6822
|
if (!cached || Date.now() - cached.at > 6e5) {
|
|
6811
6823
|
cached = { at: Date.now(), prices: await this.api.catalogue() };
|
|
6812
|
-
catalogues.set(
|
|
6824
|
+
catalogues.set(key, cached);
|
|
6813
6825
|
}
|
|
6814
6826
|
entry = cached.prices.find((p) => p.model === this.model && p.contextWindow);
|
|
6815
6827
|
} catch {
|
|
@@ -7450,7 +7462,10 @@ ${header.summary.text}` }, { role: "assistant", content: "Understood. Continuing
|
|
|
7450
7462
|
/** Le magasin de points de cette session, créé au premier besoin. */
|
|
7451
7463
|
_checkpoints() {
|
|
7452
7464
|
if (!this.checkpointsOption || !this.memory || this.role) return null;
|
|
7453
|
-
if (!this.checkpointStore)
|
|
7465
|
+
if (!this.checkpointStore) {
|
|
7466
|
+
const excludePaths = this.machine?.managedBy === "iagenify" && this.machine?.service === "object" ? ["Chats"] : [];
|
|
7467
|
+
this.checkpointStore = createCheckpoints({ files: this._files(), sessionId: this.id, excludePaths });
|
|
7468
|
+
}
|
|
7454
7469
|
return this.checkpointStore;
|
|
7455
7470
|
}
|
|
7456
7471
|
/** Enregistre l'espace de travail avant ce message. Un instantané impossible n'empêche jamais de répondre. */
|
|
@@ -7913,8 +7928,7 @@ ${summary.message.content}` }, { role: "assistant", content: "Understood. Contin
|
|
|
7913
7928
|
emit({ type: "rewound", ...rewound });
|
|
7914
7929
|
}
|
|
7915
7930
|
const root = await this._root();
|
|
7916
|
-
await this._loadLibrary();
|
|
7917
|
-
await this._loadMcp();
|
|
7931
|
+
await Promise.all([this._loadLibrary(), this._loadMcp()]);
|
|
7918
7932
|
const parsed = await this._parseInput(raw);
|
|
7919
7933
|
const restore = this._applyRunOptions(parsed.options);
|
|
7920
7934
|
try {
|
|
@@ -7948,8 +7962,7 @@ ${summary.message.content}` }, { role: "assistant", content: "Understood. Contin
|
|
|
7948
7962
|
emit({ type: "question_result", id, answer: answer ?? "" });
|
|
7949
7963
|
return answer;
|
|
7950
7964
|
} : null;
|
|
7951
|
-
this.storageContext = this.parent ? this.parent.storageContext : await this._loadStorageContext();
|
|
7952
|
-
this.memories = this.parent ? this.parent.memories : await this._loadMemories();
|
|
7965
|
+
[this.storageContext, this.memories] = this.parent ? [this.parent.storageContext, this.parent.memories] : await Promise.all([this._loadStorageContext(), this._loadMemories()]);
|
|
7953
7966
|
const context = { files: this._files(), shell: this.shell, terminals: this._terminals(), mode: () => this.mode, root, api: this.api, todos: this.todos, signal: this.controller.signal, askUser };
|
|
7954
7967
|
const usage = this.usage = { credits: 0, turns: 0, toolCalls: 0 };
|
|
7955
7968
|
let stopReason = "end_turn";
|
|
@@ -9034,6 +9047,49 @@ var ComputeResource = class {
|
|
|
9034
9047
|
};
|
|
9035
9048
|
|
|
9036
9049
|
// src/resources/mail.js
|
|
9050
|
+
function octetsEnBase64(octets) {
|
|
9051
|
+
if (typeof Buffer !== "undefined") return Buffer.from(octets.buffer, octets.byteOffset, octets.byteLength).toString("base64");
|
|
9052
|
+
let binaire = "";
|
|
9053
|
+
for (let i = 0; i < octets.length; i += 32768) binaire += String.fromCharCode(...octets.subarray(i, i + 32768));
|
|
9054
|
+
return btoa(binaire);
|
|
9055
|
+
}
|
|
9056
|
+
var nomDe = (chemin) => String(chemin).split(/[\\/]/).pop();
|
|
9057
|
+
async function encoderPiece(piece, index) {
|
|
9058
|
+
if (!piece || typeof piece !== "object") {
|
|
9059
|
+
throw new TypeError(`attachments[${index}] doit \xEAtre un objet { filename, content } ou { path }.`);
|
|
9060
|
+
}
|
|
9061
|
+
let { filename, content } = piece;
|
|
9062
|
+
if (content == null && piece.path) {
|
|
9063
|
+
if (typeof process === "undefined" || !process.versions?.node) {
|
|
9064
|
+
throw new TypeError(`attachments[${index}].path ne fonctionne que dans Node : passez content (octets ou Blob) ailleurs.`);
|
|
9065
|
+
}
|
|
9066
|
+
const { readFile } = await import("node:fs/promises");
|
|
9067
|
+
content = await readFile(piece.path);
|
|
9068
|
+
filename ??= nomDe(piece.path);
|
|
9069
|
+
}
|
|
9070
|
+
if (content == null) throw new TypeError(`attachments[${index}] n'a ni content ni path.`);
|
|
9071
|
+
let base64;
|
|
9072
|
+
if (typeof content === "string") {
|
|
9073
|
+
base64 = piece.encoding === "base64" ? content.replace(/\s+/g, "") : octetsEnBase64(new TextEncoder().encode(content));
|
|
9074
|
+
} else if (typeof Blob !== "undefined" && content instanceof Blob) {
|
|
9075
|
+
base64 = octetsEnBase64(new Uint8Array(await content.arrayBuffer()));
|
|
9076
|
+
filename ??= content.name;
|
|
9077
|
+
} else if (content instanceof ArrayBuffer) {
|
|
9078
|
+
base64 = octetsEnBase64(new Uint8Array(content));
|
|
9079
|
+
} else if (ArrayBuffer.isView(content)) {
|
|
9080
|
+
base64 = octetsEnBase64(new Uint8Array(content.buffer, content.byteOffset, content.byteLength));
|
|
9081
|
+
} else {
|
|
9082
|
+
throw new TypeError(`attachments[${index}].content doit \xEAtre un Buffer, un Uint8Array, un ArrayBuffer, un Blob ou une cha\xEEne.`);
|
|
9083
|
+
}
|
|
9084
|
+
const sortie = { filename: filename || `piece-${index + 1}`, content: base64 };
|
|
9085
|
+
if (piece.contentType) sortie.contentType = piece.contentType;
|
|
9086
|
+
if (piece.cid) sortie.cid = piece.cid;
|
|
9087
|
+
return sortie;
|
|
9088
|
+
}
|
|
9089
|
+
async function encodeAttachments(attachments) {
|
|
9090
|
+
if (!Array.isArray(attachments)) throw new TypeError("attachments doit \xEAtre une liste.");
|
|
9091
|
+
return Promise.all(attachments.map(encoderPiece));
|
|
9092
|
+
}
|
|
9037
9093
|
var Aliases = class {
|
|
9038
9094
|
constructor(client, mailbox) {
|
|
9039
9095
|
this.client = client;
|
|
@@ -9148,9 +9204,29 @@ var Mailbox = class {
|
|
|
9148
9204
|
* envoi-là. Quand elle demande l'image de la boîte, celle-ci voyage **dans** le message (`cid:`) : c'est la
|
|
9149
9205
|
* seule façon qu'un destinataire la voie, la pastille de son client étant dessinée depuis ses données à lui.
|
|
9150
9206
|
*/
|
|
9151
|
-
|
|
9207
|
+
/*
|
|
9208
|
+
* P82 (approuvé le 2026-11-18) — pièces jointes et Cci, dans la forme de nodemailer :
|
|
9209
|
+
*
|
|
9210
|
+
* await boite.send({
|
|
9211
|
+
* to: ["client@acme.com"], bcc: ["compta@moi.com"],
|
|
9212
|
+
* subject: "Votre facture",
|
|
9213
|
+
* html: '<h1>Merci</h1><img src="cid:logo">',
|
|
9214
|
+
* attachments: [
|
|
9215
|
+
* { filename: "facture.pdf", content: buffer, contentType: "application/pdf" },
|
|
9216
|
+
* { filename: "logo.png", content: png, cid: "logo" },
|
|
9217
|
+
* { filename: "devis.pdf", path: "./devis.pdf" }, // Node seulement
|
|
9218
|
+
* ],
|
|
9219
|
+
* });
|
|
9220
|
+
* // → { …, attachments: [{ filename, size, contentType, inline }] }
|
|
9221
|
+
*
|
|
9222
|
+
* `content` : Buffer, Uint8Array, ArrayBuffer, Blob, ou une chaîne — du texte UTF-8, sauf avec
|
|
9223
|
+
* `encoding: "base64"`, exactement comme nodemailer. 25 Mo au total ; les exécutables sont refusés.
|
|
9224
|
+
*/
|
|
9225
|
+
async send({ to = [], cc = [], bcc = [], subject = "", text: text2 = "", html = "", replyTo = null, signature: signature2, attachments } = {}) {
|
|
9152
9226
|
const corps = { to, cc, subject, text: text2, html, replyTo };
|
|
9227
|
+
if (bcc && (!Array.isArray(bcc) || bcc.length)) corps.bcc = bcc;
|
|
9153
9228
|
if (signature2 === false) corps.signature = false;
|
|
9229
|
+
if (attachments != null) corps.attachments = await encodeAttachments(attachments);
|
|
9154
9230
|
const res = await this.client.post(`/api/mail/${this.id}/send`, corps);
|
|
9155
9231
|
return res.sent;
|
|
9156
9232
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iagenify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "IaGenify client and agent engine — the agent loop runs inside the SDK (tools, skills, sub-agents, terminals, sessions, memory) in Node, the browser and Cloudflare Workers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|