@finalai/agent-provider 0.20.1 → 0.20.3

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.
Files changed (2) hide show
  1. package/package.json +4 -5
  2. package/HOSTING.md +0 -377
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finalai/agent-provider",
3
- "version": "0.20.1",
3
+ "version": "0.20.3",
4
4
  "private": false,
5
5
  "description": "Provider contracts for the agent stack: the agent document, requirements and inference, harnesses, sandboxes (handle, wire, grants, setups, MCP projection), the code host, channels, and the conformance kit.",
6
6
  "license": "Apache-2.0",
@@ -8,8 +8,7 @@
8
8
  "dist",
9
9
  "README.md",
10
10
  "LICENSE",
11
- "NOTICE",
12
- "HOSTING.md"
11
+ "NOTICE"
13
12
  ],
14
13
  "type": "module",
15
14
  "sideEffects": false,
@@ -242,8 +241,8 @@
242
241
  },
243
242
  "dependencies": {
244
243
  "@agentclientprotocol/sdk": "2.7.0",
245
- "@finalai/acp-session": "0.10.1",
246
- "@finalai/agent-protocol": "0.23.0",
244
+ "@finalai/acp-session": "0.10.3",
245
+ "@finalai/agent-protocol": "0.23.3",
247
246
  "@modelcontextprotocol/client": "^2.1.0",
248
247
  "@modelcontextprotocol/core": "^2.1.0",
249
248
  "@modelcontextprotocol/server": "^2.4.0",
package/HOSTING.md DELETED
@@ -1,377 +0,0 @@
1
- # Hosting agents: requirements, provide documents and local hosts
2
-
3
- An agent is a document (data) that states what it requires: a harness within a
4
- permission ceiling, compute by capability, and named integration slots. Whoever
5
- starts work provides implementations in a plain `provide` object. This guide is
6
- for hosts that implement the agent platform API these packages call: what the
7
- SDK sends, what it expects back, and the connection a client dials to lend its
8
- own process to an agent.
9
-
10
- ## Selecting a deployment
11
-
12
- ```sh
13
- export FINAL_API_HOST=https://<agents-api-host>
14
- export FINAL_API_KEY=<api-key>
15
- export FINAL_PROJECT_ID=<project-id>
16
- pnpm exec final-agents print ./agent.ts # the document, as JSON; calls nothing
17
- pnpm exec final-agents publish ./agent.ts --name release-scout
18
- ```
19
-
20
- `--host` overrides `FINAL_API_HOST`; `--project` overrides `FINAL_PROJECT_ID`.
21
- `createClient({ host })` selects a deployment the same way. Nothing in an agent
22
- names a deployment, a server URL or a credential, so the same document runs
23
- against any host.
24
-
25
- ## Agents are documents
26
-
27
- An agent value (`defineAgent`) becomes its document with `documentOf(agent)`:
28
- identity, instructions, skills, `require`, workspace seed files, each tool's
29
- name and schema, hooks, tool policy, secret names and schedules. The agent's
30
- identity is the content hash of the canonical document with defaults applied
31
- (`agentDocumentHash` from `@finalai/agent-provider/document`, `sha256:<hex>`).
32
- Hosts must hash with that function; any other canonicalization yields other
33
- hashes.
34
-
35
- Each tool and hook says where it runs:
36
-
37
- - **Serverless** code carries one self-contained ES module (`source`, `export`).
38
- It runs on the host's serverless runtime from the document alone, whether or
39
- not any client is connected. Hosts re-check that the source imports nothing.
40
- - **In-process** code carries only its interface. Its body never leaves the
41
- process that created the session; the host calls it over that process's
42
- local host connection (below). With no such connection the tool reports
43
- itself unavailable and the session carries on.
44
-
45
- `@finalai/agent-provider/code-host` routes each call by placement
46
- (`createCodeHost`); the serverless runtime contract is `ServerlessRuntimeIface`.
47
- A serverless tool gives the model a projection apart from its structured output
48
- by returning `{ [Symbol.for(SERVERLESS_TOOL_RESULT)]: true, output, modelOutput }`;
49
- the runtime reads every tool return with `serverlessToolResultOf` and sends
50
- `modelOutput` on the result line. The model sees `modelOutput` when present,
51
- and `output` stays the structured result.
52
-
53
- Routes, under `/api/v1/projects/:projectId/agents`:
54
-
55
- | Route | Body / query | Response |
56
- | ---------------- | ----------------------------------- | -------------------------------------- |
57
- | `PUT /documents` | `{ document \| source, hash? }` | `{ hash }`; refuse a hash that differs |
58
- | `POST /publish` | `{ name, hash }` | `{ id, name, hash, publishedAt }` |
59
- | `GET /lookup` | exactly one of `name`, `id`, `hash` | `agentInfoSchema` |
60
- | `GET /history` | `name`, `cursor?`, `limit?` | `agentHistorySchema` |
61
-
62
- An agent is always passed as an object, `{ hash, document? }`, never a name. A
63
- request whose document is absent names a hash the host already stores.
64
-
65
- A store sends either the document or its `source` (`agentSourceSchema`): the
66
- files the document is made from, by path. A host given `source` makes the
67
- document from those files itself and keeps them with it. It refuses a source
68
- that does not make a document (`agent_source_invalid`, with
69
- `details.diagnostics`) and, when `hash` is sent, one whose document hashes
70
- differently (`hash_mismatch`). `GET /lookup` returns the kept files as `source`
71
- (null when there are none).
72
-
73
- Every publication keeps its source: `POST /publish` refuses a hash stored without one. A host
74
- that keeps drafts makes a publication made elsewhere the next draft, and refuses one that lacks
75
- what was published from drafts since its publisher last published (`draft_conflict`), keeping
76
- the merge as the newest draft.
77
-
78
- ## Provide documents
79
-
80
- ```json
81
- {
82
- "harness": {
83
- "harness": "pi",
84
- "configuration": {
85
- "model": "gpt-6.1-sol",
86
- "inference": [{ "source": "final", "billTo": "project" }]
87
- }
88
- },
89
- "compute": { "files": "asbx_01J…", "shell": "asbx_01J…" },
90
- "integrations": { "issues": "intg_01H…" }
91
- }
92
- ```
93
-
94
- `provideDocumentSchema` (`@finalai/agent-protocol/agent-platform`) is the one
95
- shape on every call that can start work: `sessions.create`, `conversations.create`
96
- (per participant, plus a shared document for the conversation), direct and Home
97
- conversations, `addParticipant`, `PUT …/participants/:pid/provide`, channel
98
- installs (`agents.provide`) and schedules. It names only things that exist: a
99
- sandbox or integration by id, harness settings inline. Hosts store it as given
100
- and resolve participant, then conversation, then the install or schedule that
101
- created the conversation, taking each top-level key whole from the nearest scope
102
- that sets it. A conversation returns its shared document as `provide`, so a
103
- client can run the same check before adding a participant. Nothing has a
104
- default on the host.
105
-
106
- `files` and `shell` must name the same sandbox. A sandbox or integration id
107
- must belong to the session's project.
108
-
109
- ## The requirements check
110
-
111
- Every call that can start work runs `unmetRequirements` from
112
- `@finalai/agent-provider/requirements-check` with what the host knows (each
113
- sandbox's capabilities, which integrations exist, the composed harness via
114
- `harnessCheckInputOf`, whether a client holding the in-process code is
115
- connected). If anything is unmet, nothing is created and the response is:
116
-
117
- ```json
118
- {
119
- "error": {
120
- "code": "requirements_unmet",
121
- "message": "…",
122
- "details": {
123
- "agent": "sha256:…",
124
- "requirements": [
125
- {
126
- "kind": "integration",
127
- "name": "issues",
128
- "description": "Issue tracker",
129
- "problem": "not_provided",
130
- "detail": null
131
- }
132
- ]
133
- }
134
- }
135
- }
136
- ```
137
-
138
- `harness_unsuitable` has the same body for a harness change refused on its own.
139
- The SDK runs the same function before sending, so a caller sees the same list
140
- either way; the SDK error carries `code` and `requirements`
141
- (`isRequirementsUnmetError`).
142
-
143
- A running agent therefore always has what it requires: the host adds nothing to
144
- its context about requirements. An optional requirement that was not provided is
145
- simply absent.
146
-
147
- ## Harnesses, ACP adapters and environments
148
-
149
- Three independent pieces reach a model loop, and the host speaks only ACP v2:
150
-
151
- - a **harness** definition: the agent program (it need not speak ACP);
152
- - an **ACP adapter** definition: maps one harness interface to ACP v2, reusable
153
- across harnesses; a harness that speaks ACP v2 needs none;
154
- - an **environment**: a sandbox that runs them, or an ACP v2 endpoint already
155
- running at a URL.
156
-
157
- Harness settings name them:
158
- `{ harness, adapter?, configuration, environment? }`. `adapter` defaults to the
159
- harness definition's. `environment` is a sandbox id (the pair is started
160
- there), `{ url, hop? }` (nothing is started), or absent: a harness that uses
161
- `files` or `shell` natively then runs in the sandbox provided for `shell`; any
162
- other harness is refused.
163
-
164
- Definitions are data (`harnessDefinitionSchema`, `acpAdapterDefinitionSchema`
165
- in `@finalai/agent-provider/harness-definition`), published by name and stored
166
- by content hash. A harness definition carries its configuration's JSON Schema,
167
- supported features, `lowestPermission`, accepted inference sources, what it uses
168
- natively from where it runs (`native.files`, `native.shell`), its interface and
169
- default adapter, ACP behaviour (`promptWhileRunning`, `sessionSurvivesDisconnect`,
170
- `supports`, `mcp`, `consumes`), and `run` entries per runtime kind:
171
-
172
- - `process`: a command, with arguments and environment derived from the
173
- configuration by templates (`{{configuration.model}}`, groups included
174
- `when` a value is set). An adapter's process entry wraps the harness's
175
- (`{{harness.command}}`, `{ spread: 'harness.args' }`).
176
- - `worker`: a program built for a worker runtime, by name.
177
-
178
- An environment runs what its sandbox provider declares
179
- (`SandboxEnvironmentImplementationIface.runtimes`: `process`, `worker`; absent
180
- means `process` when it offers `shell`). A worker runtime is not a machine: it
181
- offers the model no files or shell, so a harness running there reaches the
182
- sandboxes provided for them over the handle RPC. `composeHarness` picks a
183
- runtime kind the environment, the harness and the adapter all have, and
184
- `harnessCheckInputOf` turns the result into the requirements check's input: a
185
- harness's native capabilities are its environment's, so only that sandbox may
186
- be provided for them. `harnessStartFor` renders what to start.
187
-
188
- A harness provider (`HarnessProviderIface`, `@finalai/agent-provider/harness-provider`)
189
- reaches a harness: `open` and `resume` return an ACP endpoint (`ws`, `http`, or
190
- `sandbox`: a process or worker program the session service starts in the
191
- environment sandbox over the handle RPC, ACP on its stdio or stream, with no
192
- port exposed), and `park`, `close` and `health` follow its lifecycle. The
193
- general provider starts adapter(harness) from the definitions; a definition
194
- whose harness is reached some other way carries its own provider code
195
- (`defineHarnessProvider`), one self-contained module run on the serverless
196
- runtime.
197
-
198
- Routes, under `/api/v1/projects/:projectId`:
199
-
200
- | Route | Body or query | Response |
201
- | ------------------------------------------ | ------------------------------------ | --------------------------------- |
202
- | `POST /harnesses/check` | `{ agent: hash, harness, compute? }` | `harnessCheckResponseSchema` |
203
- | `POST /harnesses/publish` | `{ name, definition, hash? }` | `definitionPublicationSchema` |
204
- | `GET /harnesses/lookup` | `name` or `hash` | `harnessDefinitionInfoSchema` |
205
- | `GET /harnesses` | | `harnessDefinitionListSchema` |
206
- | `POST /acp-adapters/publish` | `{ name, definition, hash? }` | `definitionPublicationSchema` |
207
- | `GET /acp-adapters/lookup` | `name` or `hash` | `acpAdapterDefinitionInfoSchema` |
208
- | `GET /acp-adapters` | | `acpAdapterDefinitionListSchema` |
209
- | `GET /subscription-allowances` | | `subscriptionAllowanceListSchema` |
210
- | `PUT /subscription-allowances/:harness` | `{}` | `subscriptionAllowanceSchema` |
211
- | `DELETE /subscription-allowances/:harness` | | `{ ok }` |
212
-
213
- The check answers `{ suitable, problems, compute, environment, adapter,
214
- runtime }`, where `compute[capability].status` is `harness` (its environment
215
- serves it natively), `sandbox` (a provided sandbox must) or `unavailable`. A
216
- project can name its own definitions, its ancestors' and the public catalog's.
217
- A subscription inference source reaches a harness only when the project allows
218
- that harness, or the public catalog does for its own definitions. The model is
219
- a string the harness validates; the host never substitutes a default model.
220
-
221
- ## Sandboxes and setups
222
-
223
- Under `/api/v1/projects/:projectId`: `POST /sandboxes` (`{ provider, environment,
224
- setup?, ownedBy?, idempotencyKey? }`; creating boots nothing), `GET` and
225
- `DELETE /sandboxes/:id`, `GET /sandboxes/:id/description`, and
226
- `POST /sandboxes/:id/run` (`{ command, cwd?, env?, timeoutMs? }` →
227
- `{ exitCode, stdout, stderr }`, booting the sandbox if needed). A sandbox owned
228
- by a conversation or session is deleted with its owner. A retried create with
229
- the same `idempotencyKey` returns the first sandbox. Sandbox setups are
230
- published with `POST /sandbox-setups` (`{ name, setup }`); `latest` resolves once,
231
- when a sandbox is created.
232
-
233
- ## Integrations and sign-in
234
-
235
- Integrations are project resources: an MCP server and how calls to it
236
- authenticate (`oauth` personal or shared, `secret` by project secret name,
237
- `platform-identity`, `none`). A person's own sign-in is runtime state: on the
238
- first call that needs it, the host raises a `sign_in` decision for that person,
239
- holds the call, and continues it when `POST /api/v1/sign-ins/complete` succeeds.
240
- `platform-identity` sends a short-lived signed assertion of the calling session
241
- that any server can verify against the host's published keys; Final's gateway is
242
- an ordinary integration with this auth.
243
-
244
- ### Integration tool policy
245
-
246
- A slot's `tools` (`allow`, `deny`, `load`, `allowAnnotations`,
247
- `denyAnnotations`) and `approvals` are a ceiling over whatever integration fills
248
- it. Keys are tool names or `*` patterns: `*` matches any run of characters,
249
- `deny` wins over `allow`, and the most specific key governs (an exact name, else
250
- the pattern with the most literal characters, ties toward `ask`). Hosts enforce
251
- this with `isToolExposed`, `isToolLoaded`, `toolApprovalOf` and
252
- `resolveToolApprovalKey` from `@finalai/agent-provider`.
253
-
254
- An annotation selector matches when every hint it sets equals the tool's hint,
255
- reading omitted hints as the MCP spec's defaults (not read-only, destructive, not
256
- idempotent, open world). Annotations come from the integration's server, so
257
- select on them only for servers trusted to classify their own tools.
258
-
259
- With `load`, the host lists only the loaded tools and keeps every other exposed
260
- tool reachable through a search over the integration's remaining tools and a
261
- call that runs a found tool by its real name, with the same exposure and
262
- approval checks as a direct call. Without `load`, the host lists every exposed
263
- tool except tools a server labels with a connector in `_meta`
264
- (`{ "ai.final/connector": { "namespace": "…", "name": "…" } }`) and tools past
265
- the host's listing limit, which it searches instead. A harness that declares
266
- `supports.deferredToolSearch` searches tools itself, so the host lists every
267
- exposed tool to it.
268
-
269
- ## Local hosts
270
-
271
- A client that starts an agent can lend its own process to it: it serves the
272
- agent's `files` and `shell` (any it was not given a sandbox for, unless created
273
- with `localCompute: false`) and answers calls to the agent's in-process tools,
274
- hooks and approval predicates. It does so over one WebSocket per agent it
275
- started:
276
-
277
- ```
278
- GET /api/v1/projects/:projectId/local-hosts (WebSocket upgrade)
279
- Sec-WebSocket-Protocol: final.local-host.v1
280
- Authorization: Bearer <the client's credential>
281
- ```
282
-
283
- The socket carries two protocols. Binary frames are always the sandbox handle
284
- RPC's stream chunks. A text frame belongs to the **host protocol** when it is a
285
- JSON-RPC request or notification whose method starts with `host/` or `code/`, or
286
- a response (or `$/cancel_request`) whose id is a string starting with `host:`.
287
- Every other text frame is the **sandbox handle RPC**
288
- (`@finalai/agent-provider/sandbox/wire`), in which the host is the RPC client and
289
- the client process serves the sandbox: the host sends `initialize`,
290
- `sandbox/readFile`, `sandbox/run` and the rest, with numeric ids, gated by a grant
291
- of the access the agent requires on the capabilities it serves.
292
- `splitLocalHostChannel` and `createHostPeer` from `@finalai/agents/client/local-host`
293
- implement both sides of the split.
294
-
295
- **`host/hello`** (client → host, first): the client's id is `host:1`.
296
-
297
- ```json
298
- {
299
- "jsonrpc": "2.0",
300
- "id": "host:1",
301
- "method": "host/hello",
302
- "params": {
303
- "protocolVersion": 1,
304
- "owner": { "kind": "session", "id": "ases_…" },
305
- "agent": "sha256:…",
306
- "capabilities": ["files", "shell"],
307
- "tools": ["find_order"],
308
- "hooks": [],
309
- "approvals": [],
310
- "resume": "lhost_…"
311
- }
312
- }
313
- ```
314
-
315
- `owner.kind` is `session` or `conversation`; `owner.id` is absent when the
316
- caller chose no id, and the host reserves one the client then creates with.
317
- `resume` is a host id from an earlier connection. The result:
318
-
319
- ```json
320
- {
321
- "jsonrpc": "2.0",
322
- "id": "host:1",
323
- "result": {
324
- "hostId": "lhost_…",
325
- "owner": { "kind": "session", "id": "ases_…" },
326
- "sandboxId": "asbx_…"
327
- }
328
- }
329
- ```
330
-
331
- `sandboxId` names this connection's compute in `provide.compute` (one sandbox for
332
- both capabilities, as the requirements check demands); it is null when the
333
- client serves no capability. The sandbox belongs to the owner and is deleted
334
- with it.
335
-
336
- **`code/run`** (host → client): params are one code invocation
337
- (`codeInvocationSchema` from `@finalai/agent-provider/code-host`: `kind` tool,
338
- hook or approval, the `name` in the document, `input` or `event` and `payload`,
339
- and a `context` with `sessionId`, `callId`, `actingUserId` and the session's
340
- compute endpoints for `ctx.sandbox(capability)`). A hook's payload is
341
- `{ data, meta: { id, at, seq } }`. The result is the final line:
342
- `{ "type": "result", "output": …, "modelOutput"?: … }` or
343
- `{ "type": "error", "message": "…" }`; an approval answers `output: true` to
344
- ask first. While it runs the client sends **`code/progress`** notifications
345
- `{ "requestId": "host:7", "data": …, "label"?: "…" }`. The host cancels with
346
- `$/cancel_request { "requestId": "host:7" }`.
347
-
348
- **`code/secret`** (client → host): in-process code reading `ctx.secrets.get(name)`
349
- asks with `{ "requestId": "host:7", "name": "BILLING_TOKEN" }`, where
350
- `requestId` is the `code/run` it runs for. The host answers
351
- `{ "value": "…" | null }` (null when the secret is not set). It refuses a name
352
- the agent's document does not list in `secrets`, a `requestId` that is not a
353
- `code/run` in flight on this connection, and resolves the name in the project
354
- of the session or conversation the host serves. The client refuses unlisted
355
- names itself before asking.
356
-
357
- When the socket closes the session carries on. Until a connection resumes it,
358
- the host reports this process's in-process tools as unavailable
359
- (`CodeErrorCode.Unavailable`) and its sandbox as unreachable. The SDK's socket
360
- does not keep a Node process alive, so a script that is done exits and its tools
361
- become unavailable.
362
-
363
- ## Host integration
364
-
365
- These packages define contracts and client behaviour, not a platform. A host
366
- implementing them must:
367
-
368
- 1. Store documents by `agentDocumentHash`, re-check self-contained serverless
369
- source, make documents from agent `source` without giving that code network
370
- or host access, and point names at hashes only when someone publishes.
371
- 2. Run `unmetRequirements` on every call that starts work and at every session
372
- open, and create nothing when it fails.
373
- 3. Store each `provide` as given; never fill a requirement on a caller's behalf.
374
- 4. Route each tool and hook by its placement: serverless code to its runtime with
375
- the source from the document, in-process code to the local host that holds it.
376
- 5. Resolve integration auth per call for the acting person, raising sign-in as
377
- that integration's auth step.