@finalai/final-agent-provider 0.1.2 → 0.1.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.
package/HOSTING.md ADDED
@@ -0,0 +1,165 @@
1
+ # Portable agent definitions and hosted bindings
2
+
3
+ An agent declares behavior and logical resources. Hosting supplies endpoints,
4
+ resource identifiers, and credential references. The same compiled source can
5
+ resolve against dev and production configuration without source edits.
6
+
7
+ ## Selecting a deployment
8
+
9
+ ```sh
10
+ export FINAL_API_HOST=https://agent-session.primary-dev.final.ai/api
11
+ export FINAL_API_KEY=<dev-organization-key>
12
+ pnpm exec final-agents build ./agent
13
+ pnpm exec final-agents publish ./agent --agent my-agent
14
+ ```
15
+
16
+ Choose production by changing the host and organization key. `--host` overrides
17
+ `FINAL_API_HOST`; without either, the existing production default remains. Build
18
+ compiles locally and optionally checks installed-harness compatibility. Publish
19
+ compiles again and sends source/release requests to the selected deployment.
20
+ Neither rewrites authored URLs. A GitHub-backed definition uses remote source;
21
+ push edits before explicitly publishing a ref. Caller API keys never become agent
22
+ credentials merely because they were used to publish.
23
+
24
+ ## Hosted connections
25
+
26
+ ```ts
27
+ import { defineHostedConnection } from '@finalai/agents';
28
+
29
+ export default defineHostedConnection({
30
+ binding: 'issue-tracker',
31
+ tools: { allow: ['read_issue'], deny: ['delete_issue'] },
32
+ });
33
+ ```
34
+
35
+ `issue-tracker` is an example configuration name, not a built-in service.
36
+ Hosting configures it with non-secret JSON:
37
+
38
+ ```json
39
+ {
40
+ "url": "https://issues.dev.example/mcp",
41
+ "auth": { "secretKey": "ISSUE_TRACKER_TOKEN", "headerName": null },
42
+ "headers": { "X-Workspace": "development" }
43
+ }
44
+ ```
45
+
46
+ Production supplies another value under the same name. The helper uses an ordinary
47
+ `defineDynamic` connection at `session.started`, then the usual HTTP MCP lowering,
48
+ validation, permissions, and credential broker. Hosting supplies transport settings,
49
+ not tool policies. URL, authentication references, transport headers belong to hosting; the hosted helper does
50
+ not accept authored overrides for these fields. Referenced secrets still need the agent's secret allowlist and normal
51
+ authorization. Actual tokens must not be returned in configuration headers.
52
+
53
+ Final uses the same generic helper:
54
+
55
+ ```ts
56
+ import { defineFinalConnection } from '@finalai/agents';
57
+
58
+ export default defineFinalConnection({
59
+ tools: { deny: ['create_agent_session'] },
60
+ });
61
+ ```
62
+
63
+ This resolves the `final` binding. Hosting supplies its URL and
64
+ `auth: { kind: 'final-session' }`, just as it supplies authentication for any
65
+ other hosted connection. `binding`
66
+ selects another name. Existing explicit `url` calls remain static and compatible;
67
+ they always point at that URL. There is no Final-specific compiler rewrite.
68
+
69
+ ## Resources and provider packages
70
+
71
+ `HostedBindingsIface` is the shared `@finalai/agent-provider` contract. Hosting
72
+ implements `get(name)` to return scoped JSON or null. `requireHostedBinding` rejects
73
+ missing hosting, absent names, and invalid JSON without an environment fallback.
74
+ Names are configuration keys, not global permissions or inferred URLs.
75
+
76
+ Tools, hooks, dynamic resolvers, sandbox selectors, and harness/sandbox/channel
77
+ provider contexts expose an optional `bindings` reader. A third-party resolver can
78
+ use the same reader for model or resource configuration:
79
+
80
+ ```ts
81
+ import { defineDynamic, requireHostedBinding } from '@finalai/agents';
82
+
83
+ export const model = defineDynamic({
84
+ requiredBindings: [{ name: 'primary-model', schema: { type: 'string', minLength: 1 } }],
85
+ description: 'The deployment model',
86
+ preview: 'Resolved from primary-model',
87
+ events: {
88
+ 'session.started': async (_event, ctx) =>
89
+ requireHostedBinding({ bindings: ctx.bindings, name: 'primary-model' }),
90
+ },
91
+ });
92
+ ```
93
+
94
+ Use that value in a harness configuration supporting dynamic models. A resource
95
+ binding can similarly contain a repository, guide slug, device ID, or non-secret
96
+ SDK base URL; the consumer validates the resource-specific schema. Literal IDs,
97
+ custom URLs, and external credential choices are never silently rewritten.
98
+
99
+ Installed providers already accept factory configuration injected by hosting.
100
+ Keep supplying deployment service URLs there. Computer/WebSocket clients retain
101
+ explicit configuration; a hosted provider can obtain it through this shared reader.
102
+ Package versions stay pinned. Packages do not read a global DEV/PROD flag.
103
+
104
+ ## Declared requirements and user experience
105
+
106
+ `defineHostedConnection` declares its binding name and JSON configuration schema
107
+ in the compiled dynamic slot automatically. Other dynamic consumers declare
108
+ `requiredBindings` as in the model example. Hosts can inspect these requirements
109
+ without running authored resolvers. Repeated names must satisfy every declared
110
+ schema; names are looked up once per preflight.
111
+
112
+ Before accepting a release, hosting calls
113
+ `validateHostedBindings({ manifest, bindings })` with a reader scoped to the
114
+ selected deployment, organization, and agent. Hosts compiling source can instead
115
+ pass `hostedBindings` to `compile`; failed preflight returns error diagnostics and
116
+ no manifest or bundle. An offline build can still compile and expose requirements
117
+ without accessing deployment configuration. The CLI does not yet fetch binding
118
+ configuration itself: server-side publication must enable this preflight.
119
+
120
+ When dev is selected, lookups use only dev configuration. A missing dev binding
121
+ fails even if production has the same name; never retry against production or
122
+ substitute a production default. Changing the CLI host selects where to publish;
123
+ the runtime reader comes from that deployment, not from the author's environment.
124
+ Explicit authored URLs retain their literal destination.
125
+
126
+ Authors keep one source definition. Operators configure its named connections
127
+ and resources once in each deployment. End users start the agent as usual; an
128
+ unconfigured required resource produces a configuration failure instead of a
129
+ session silently missing tools. Dynamic handlers validate declared requirements
130
+ before running. Shared manifest resolution rejects null results for required slots,
131
+ even if a host catches a resolver exception and returns null. Hosts must propagate
132
+ that failure to startup. Session-started values stay pinned across turns and resume.
133
+
134
+ This PR adds no configuration UI. A host can use the compiled requirements to show
135
+ which names need configuration and return an actionable deployment-specific error.
136
+
137
+ ## Host integration
138
+
139
+ These packages implement contracts and authored runtime behavior, not a deployment
140
+ configuration store or RPC service. Existing hosting needs to:
141
+
142
+ 1. Resolve names within the authorized deployment, organization, and agent; never
143
+ expose the process environment or an unrestricted cross-tenant registry.
144
+ 2. Inject `bindings` into lifecycle resolution and the tool/hook/selector/provider
145
+ contexts using it. Dynamic approval evaluation and tool reconstruction after
146
+ isolate eviction need the same reader. Readers and tokens are not persisted in
147
+ boundary snapshots.
148
+ 3. Configure `final` with that deployment's approved MCP endpoint. The ordinary
149
+ broker continues restricting `final-session` grants to that endpoint.
150
+ 4. Return non-secret configuration and credential references, with normal provider,
151
+ secret, resource, and organization authorization.
152
+ 5. Run the release preflight above and validate again before starting a new
153
+ session. Treat failed required-binding resolution as a startup/configuration error, not
154
+ an omitted connection or a fallback to production. Preserve existing runtime
155
+ revisions when publication fails.
156
+ 6. Retain session-started resolved values across turns/resume; resolve new sessions
157
+ against their own deployment.
158
+
159
+ Optional readers preserve source compatibility with existing hosts. Definitions
160
+ requesting bindings fail clearly if hosting does not provide them. Installing these
161
+ packages alone does not change Final's deployed service wiring or provision secrets.
162
+
163
+ New compiles emit manifest version 3, so older hosts reject them rather than
164
+ stripping required-binding metadata. Updated readers still accept persisted
165
+ version 2 revisions. Upgrade hosting before publishing newly compiled agents.
package/README.md CHANGED
@@ -10,3 +10,9 @@ the public Computers and Device APIs; the Computers transport is shared with
10
10
 
11
11
  Authoring helpers produce manifest bindings. Select the matching `/runtime/*`
12
12
  adapter when connecting your own CLI or ACP endpoint.
13
+
14
+ `defineFinalConnection()` requests the host's `final` binding at session start,
15
+ using the generic `defineHostedConnection` implementation. Its session grant still
16
+ goes through the usual credential broker. Existing calls with an explicit `url`
17
+ remain static. Hosts without a binding reader cannot run URL-free definitions;
18
+ see the repository's [hosting guide](HOSTING.md) for wiring requirements.
@@ -1,7 +1,11 @@
1
- import { type McpClientConnectionDefinitionIface } from '@finalai/agent-definition/authoring';
1
+ import { type DynamicSentinelIface, type HostedConnectionDefinitionIface, type McpClientConnectionDefinitionIface } from '@finalai/agent-definition/authoring';
2
2
  export type FinalConnectionDefinitionIface = Omit<McpClientConnectionDefinitionIface, 'auth'>;
3
- export declare const defineFinalConnection: <TConnection extends FinalConnectionDefinitionIface>(definition: TConnection) => TConnection & {
3
+ export interface FinalHostedConnectionDefinitionIface extends Omit<HostedConnectionDefinitionIface, 'binding'> {
4
+ readonly binding?: string;
5
+ }
6
+ export declare function defineFinalConnection<TConnection extends FinalConnectionDefinitionIface>(definition: TConnection): TConnection & {
4
7
  readonly auth: {
5
- readonly kind: "final-session";
8
+ readonly kind: 'final-session';
6
9
  };
7
10
  };
11
+ export declare function defineFinalConnection(definition?: FinalHostedConnectionDefinitionIface): DynamicSentinelIface<McpClientConnectionDefinitionIface>;
@@ -1,7 +1,15 @@
1
1
  import {
2
- defineMcpClientConnection
2
+ defineMcpClientConnection,
3
+ defineHostedConnection
3
4
  } from "@finalai/agent-definition/authoring";
4
- const defineFinalConnection = (definition) => defineMcpClientConnection({ ...definition, auth: { kind: "final-session" } });
5
+ function defineFinalConnection(definition = {}) {
6
+ if ("url" in definition)
7
+ return defineMcpClientConnection({ ...definition, auth: { kind: "final-session" } });
8
+ return defineHostedConnection({
9
+ ...definition,
10
+ binding: definition.binding ?? "final"
11
+ });
12
+ }
5
13
  export {
6
14
  defineFinalConnection
7
15
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/connections.ts"],
4
- "sourcesContent": ["import {\n defineMcpClientConnection,\n type McpClientConnectionDefinitionIface,\n} from '@finalai/agent-definition/authoring';\n\nexport type FinalConnectionDefinitionIface = Omit<McpClientConnectionDefinitionIface, 'auth'>;\n\n// `connections/final.ts`: Final's MCP server as an ordinary connection. The\n// session service's broker resolves `final-session` auth to a grant scoped to\n// the calling session, which Final's MCP server runs the tools as.\nexport const defineFinalConnection = <TConnection extends FinalConnectionDefinitionIface>(\n definition: TConnection,\n): TConnection & { readonly auth: { readonly kind: 'final-session' } } =>\n defineMcpClientConnection({ ...definition, auth: { kind: 'final-session' } });\n"],
5
- "mappings": "AAAA;AAAA,EACE;AAAA,OAEK;AAOA,MAAM,wBAAwB,CACnC,eAEA,0BAA0B,EAAE,GAAG,YAAY,MAAM,EAAE,MAAM,gBAAgB,EAAE,CAAC;",
4
+ "sourcesContent": ["import {\n defineMcpClientConnection,\n defineHostedConnection,\n type DynamicSentinelIface,\n type HostedConnectionDefinitionIface,\n type McpClientConnectionDefinitionIface,\n} from '@finalai/agent-definition/authoring';\n\nexport type FinalConnectionDefinitionIface = Omit<McpClientConnectionDefinitionIface, 'auth'>;\n\nexport interface FinalHostedConnectionDefinitionIface extends Omit<\n HostedConnectionDefinitionIface,\n 'binding'\n> {\n readonly binding?: string;\n}\n\n// `connections/final.ts`: Final's MCP server as an ordinary connection. The\n// session service's broker resolves `final-session` auth to a grant scoped to\n// the calling session, which Final's MCP server runs the tools as.\nexport function defineFinalConnection<TConnection extends FinalConnectionDefinitionIface>(\n definition: TConnection,\n): TConnection & { readonly auth: { readonly kind: 'final-session' } };\nexport function defineFinalConnection(\n definition?: FinalHostedConnectionDefinitionIface,\n): DynamicSentinelIface<McpClientConnectionDefinitionIface>;\nexport function defineFinalConnection(\n definition: FinalConnectionDefinitionIface | FinalHostedConnectionDefinitionIface = {},\n): McpClientConnectionDefinitionIface | DynamicSentinelIface<McpClientConnectionDefinitionIface> {\n if ('url' in definition)\n return defineMcpClientConnection({ ...definition, auth: { kind: 'final-session' } });\n return defineHostedConnection({\n ...definition,\n binding: definition.binding ?? 'final',\n });\n}\n"],
5
+ "mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAoBA,SAAS,sBACd,aAAoF,CAAC,GACU;AAC/F,MAAI,SAAS;AACX,WAAO,0BAA0B,EAAE,GAAG,YAAY,MAAM,EAAE,MAAM,gBAAgB,EAAE,CAAC;AACrF,SAAO,uBAAuB;AAAA,IAC5B,GAAG;AAAA,IACH,SAAS,WAAW,WAAW;AAAA,EACjC,CAAC;AACH;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finalai/final-agent-provider",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "private": false,
5
5
  "description": "Final's provider package: serverless, remote and local harnesses; the computer and device sandboxes; the messaging, schedule and event channels.",
6
6
  "license": "Apache-2.0",
@@ -9,6 +9,7 @@
9
9
  "README.md",
10
10
  "LICENSE",
11
11
  "NOTICE",
12
+ "HOSTING.md",
12
13
  "THIRD_PARTY_NOTICES.md"
13
14
  ],
14
15
  "type": "module",
@@ -212,14 +213,14 @@
212
213
  },
213
214
  "dependencies": {
214
215
  "@agentclientprotocol/sdk": "1.8.0",
215
- "@finalai/acp-session": "0.1.2",
216
- "@finalai/agent-protocol": "0.1.2",
217
- "@finalai/agent-provider": "0.1.2",
218
- "@finalai/computers": "0.1.2",
219
- "@finalai/websockets": "0.1.2",
216
+ "@finalai/acp-session": "0.1.3",
217
+ "@finalai/agent-protocol": "0.1.3",
218
+ "@finalai/agent-provider": "0.1.3",
219
+ "@finalai/computers": "0.1.3",
220
+ "@finalai/websockets": "0.1.3",
220
221
  "ws": "^8.21.3",
221
222
  "zod": "4.6.5",
222
- "@finalai/agent-definition": "0.1.2"
223
+ "@finalai/agent-definition": "0.1.3"
223
224
  },
224
225
  "engines": {
225
226
  "node": ">=26"