@tomato414941/foundation 0.4.0 → 0.5.1
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/guide.mjs +45 -34
- package/package.json +1 -1
- package/runtime.mjs +7 -5
package/guide.mjs
CHANGED
|
@@ -19,9 +19,11 @@ function connectorLines(connectors) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function guide(connectors) {
|
|
22
|
-
return ['Foundation
|
|
23
|
-
'A
|
|
24
|
-
'
|
|
22
|
+
return ['Foundation holds, for each principal, grants and objects, and runs explicitly requested built-in functions.',
|
|
23
|
+
'A grant is what its holder let Foundation do at a provider: a credential they handed over (given), a consent they gave',
|
|
24
|
+
'at the service (authorized), or a role they made for Foundation to assume (delegated). An object is bytes they placed here.',
|
|
25
|
+
'Reading never reaches a provider. Delivering a grant derives what it yields now: a given one its bytes, the others what',
|
|
26
|
+
'their connector obtains. A name is the holder\'s word for a thing; it decides no service, function or variable.', '',
|
|
25
27
|
'Everything below is HTTP with your approved key: Authorization: Bearer fdn_...',
|
|
26
28
|
'Nothing here needs a shell. With one, use foundation api to attach the key and foundation exec to deliver values',
|
|
27
29
|
'to a command. api prints responses: use function save options when output should not enter your context.',
|
|
@@ -46,28 +48,34 @@ export function guide(connectors) {
|
|
|
46
48
|
' POST /v1/relations {"subject":"<principal id>","relation":"viewer"|"editor","object_type":"holding","object_id":"<id>"} DELETE takes it back.',
|
|
47
49
|
' GET /v1/holdings what others have shown you. GET /v1/holdings/<id> one thing, whoever holds it.',
|
|
48
50
|
' GET /v1/holdings/<id>/content reads it; PUT writes it, as editor. Lines point at the id, so renaming changes nothing.', '',
|
|
49
|
-
'
|
|
50
|
-
' PUT /v1/holdings?kind=
|
|
51
|
+
'GRANTS (what the holder let Foundation use)',
|
|
52
|
+
' PUT /v1/holdings?kind=grant&name=<name> body: raw bytes, up to 1MB. A given grant: the same exact name',
|
|
53
|
+
' replaces that value; the answer carries its id.',
|
|
51
54
|
' What you keep for the holder you may read back (an editor line is drawn for you). What the holder kept, or a',
|
|
52
|
-
'
|
|
55
|
+
' service authorized, you may deliver into a command but not read, unless the holder draws you a line.',
|
|
53
56
|
' Do not print delivered values into your context.',
|
|
54
|
-
' GET /v1/holdings?kind=
|
|
55
|
-
'
|
|
56
|
-
' GET /v1/holdings
|
|
57
|
-
'
|
|
57
|
+
' GET /v1/holdings?kind=grant every grant: id, name, method (given / authorized / delegated), status;',
|
|
58
|
+
' for a connected one also its service, facts and the variables it yields. &method= and &prefix= narrow it.',
|
|
59
|
+
' GET /v1/holdings?kind=grant&name=<name> one given grant by name: its id and metadata. 404 if no such name.',
|
|
60
|
+
' GET /v1/holdings/<id>/content a given grant\'s bytes, as written; 403 forbidden without a line to it. PUT writes them.',
|
|
61
|
+
' A connected grant has no content to read (405): what it yields is derived when delivered.',
|
|
62
|
+
' PATCH /v1/holdings/<id> {"name"} a new name for the same thing. DELETE /v1/holdings/<id> removes it (a connected one: see below).',
|
|
58
63
|
' URL-encode the name. A name is any text, which is why it travels as a query and not as a path. Names are 1-200 characters without control characters; case, spaces, slashes and punctuation',
|
|
59
64
|
' remain literal. No normalization, hierarchy, service ownership or automatic renewal is inferred.',
|
|
60
65
|
' The owner can read, rename or delete any saved value. Stored copies survive OAuth disconnection.', '',
|
|
61
66
|
'HANDING IT TO A COMMAND',
|
|
62
|
-
' POST /v1/deliveries {"names": [{"name": "build token", "as": "GH_TOKEN"}]}',
|
|
63
|
-
' Each item is {name, as, filename?}.
|
|
67
|
+
' POST /v1/deliveries {"names": [{"name": "build token", "as": "GH_TOKEN"}, {"name": "<id of a connected grant>"}]}',
|
|
68
|
+
' Each item is {name, as, filename?}. name is a given grant\'s name or any grant\'s id. For a given grant, as is',
|
|
69
|
+
' required: it names the environment variable. A connected grant yields its connector\'s variables (see outputs);',
|
|
70
|
+
' as may rename the one variable of a connector that has exactly one. Delivering a connected grant asks the service',
|
|
71
|
+
' for a fresh credential when needed; expires_at says how long what came back is good.',
|
|
64
72
|
' filename makes the bytes a temporary file instead; as holds its local path. Use this for binary or multiline data.',
|
|
65
73
|
' Up to 16 inputs. Variables and filenames must be distinct; reserved system variables are refused.',
|
|
66
|
-
' Returns delivery: {environment, files}.
|
|
67
|
-
'
|
|
74
|
+
' Returns delivery: {environment, files}. Calling this into an agent context exposes values. Use exec when the intent',
|
|
75
|
+
' is to run a local command.', '',
|
|
68
76
|
'FILLING THE STORE',
|
|
69
77
|
'',
|
|
70
|
-
'1. Put it there yourself. Anything you obtained or wrote: PUT /v1/holdings?kind=
|
|
78
|
+
'1. Put it there yourself. Anything you obtained or wrote: PUT /v1/holdings?kind=grant&name=<name>, above.',
|
|
71
79
|
'',
|
|
72
80
|
'2. ASKING THE OWNER, for what only they can fetch -- an API token, a key, a certificate they must go and create.',
|
|
73
81
|
' POST /v1/requests {"kind":"store", "input":{"fields":[{...}]}, "purpose":"...", "steps":["..."], "valid_minutes":30}',
|
|
@@ -88,32 +96,33 @@ export function guide(connectors) {
|
|
|
88
96
|
' Give the owner the verification_uri (there is no code). When they finish, it is simply kept.',
|
|
89
97
|
' Ask for what the owner already holds. Never take it through the conversation and put it there yourself.',
|
|
90
98
|
'',
|
|
91
|
-
'3. CONNECTING A SERVICE
|
|
92
|
-
'
|
|
99
|
+
'3. CONNECTING A SERVICE, so that Foundation may obtain credentials there itself. What renews them stays with the',
|
|
100
|
+
' grant, never in a value you can read. Connecting creates one grant, listed with the others.',
|
|
93
101
|
...connectorLines(connectors),
|
|
94
102
|
' POST /v1/requests {"kind":"connect", "input":{"connector":"<id>"}, "purpose":"...", "valid_minutes":30} Give the owner the verification_uri.',
|
|
103
|
+
' To reconnect, add "connection_id":"<existing id>" inside input. This updates that connection and keeps its id.',
|
|
104
|
+
' Without connection_id, authorization creates a separate connection, even for the same service user. List and use',
|
|
105
|
+
' an existing connection when no new authorization is needed. Provider consent and revocation may affect several connections.',
|
|
106
|
+
' A connector whose flow is "role" (aws.role) has the owner make a role for Foundation in their own console and',
|
|
107
|
+
' paste its name; nothing of theirs is kept but that name, and each delivery obtains an hour of credentials.',
|
|
95
108
|
' Poll GET /v1/requests/<id> every few seconds until done; result.connection_id identifies the connection.',
|
|
96
|
-
' GET /v1/
|
|
109
|
+
' GET /v1/holdings?kind=grant lists connected grants with the others: for each, method (authorized / delegated),',
|
|
110
|
+
' service details, facts and the variables it yields. To use one, deliver it (above) or bind it in http.request (below).',
|
|
111
|
+
' DELETE /v1/holdings/<id> {"revoke": true|false} disconnects one (the owner, in a browser); revoke also asks the',
|
|
112
|
+
' service to withdraw what it granted. What was already handed out stays where it went.', '',
|
|
97
113
|
'FUNCTIONS',
|
|
98
|
-
' GET /v1/functions catalog of built-in operations and their invocation endpoints; no arbitrary-code runtime.',
|
|
99
|
-
' POST /v1/functions/connection.credentials',
|
|
100
|
-
' {"connection_id": "<id>", "save": {"<output identifier>": "<chosen saved name>"}}',
|
|
101
|
-
' Checks or renews that connection and saves only the outputs you explicitly name. Returns saved metadata and',
|
|
102
|
-
' actual expiry, without credential values. Existing values at those exact names are replaced atomically.',
|
|
103
|
-
' Omit save to receive delivery directly. Prefer save when invoking from an AI tool; then use exec or http.request.',
|
|
104
|
-
' Saving creates independent copies: subsequent reads never refresh them; invoke this function again when needed.',
|
|
105
|
-
' Disconnecting stops future processing, not copies already saved or handed out. Revoke at the provider if needed.', '',
|
|
114
|
+
' GET /v1/functions catalog of built-in operations and their invocation endpoints; no arbitrary-code runtime.', '',
|
|
106
115
|
'WHEN IT DOES NOT WORK',
|
|
107
116
|
' GET /v1/requests/<id> one of your requests, and what happened at its page (events).',
|
|
108
117
|
' GET /v1/requests?status=pending your requests. Several may be open at once (up to 10).',
|
|
109
118
|
' events is the raw record, in order: page_opened / page_viewed / connect_started / connect_failed (with a code and',
|
|
110
|
-
' Foundation\'s own message) / connected / stored / denied / cancelled. What was typed is never recorded.',
|
|
119
|
+
' Foundation\'s own message) / connect_review (awaiting confirmation of changes) / connected / stored / denied / cancelled. What was typed is never recorded.',
|
|
111
120
|
' DELETE /v1/requests/<id> cancels it. status is pending / done / denied / cancelled.',
|
|
112
121
|
' Completion and result are fixed until the request expires, even if the resulting resource changes or is removed.',
|
|
113
|
-
' Current connection state is at GET /v1/
|
|
122
|
+
' Current connection state is at GET /v1/holdings?kind=grant. Revoked keys receive 401; their pending requests are cancelled.',
|
|
114
123
|
' Request feedback expires with the request. A done result is a connection_id or the names saved at completion.',
|
|
115
124
|
' Why a registration failed: invalid_values (wrong shape) / invalid_credential (the connector would not take it) /',
|
|
116
|
-
' reconnect_required (the service rejected it) /
|
|
125
|
+
' reconnect_required (the service rejected it) / connection_changed (the target changed). A key approval shows its own events at',
|
|
117
126
|
' GET /v1/requests/<id>: confirmation_required (a wrong code) / confirmation_locked (5 tries).', '',
|
|
118
127
|
'A PLACE FOR FILES (object storage the owner did not have to sign up for)',
|
|
119
128
|
' PUT /v1/holdings?kind=object&name=<key> body is the bytes; the Content-Type you send is what a reader gets back. Up to 25MB.',
|
|
@@ -126,12 +135,14 @@ export function guide(connectors) {
|
|
|
126
135
|
'HTTPS REQUEST FUNCTION',
|
|
127
136
|
' POST /v1/functions/http.request {"url": "https://api.example.com/v1/items", "method": "POST",',
|
|
128
137
|
' "headers": {"authorization": "Bearer {{foundation:token}}"}, "bindings": {"token": "build token"}, "body": "..."}',
|
|
129
|
-
' Each placeholder identifies an input slot. bindings maps slots to
|
|
130
|
-
'
|
|
131
|
-
'
|
|
138
|
+
' Each placeholder identifies an input slot. bindings maps slots to grants: a given grant\'s exact name (including',
|
|
139
|
+
' braces or spaces), or a connected grant\'s id (<id>#<VARIABLE> when it yields several). Without bindings, a slot',
|
|
140
|
+
' is itself a name. Inputs only in headers/body, never in the URL. Up to 8 inputs. A bound connected grant is',
|
|
141
|
+
' derived first, so its service may be asked for a fresh credential.',
|
|
142
|
+
' body_encoding "base64" sends bytes without substitution.',
|
|
132
143
|
' Returns {response: {status, headers, body, body_encoding}}. Common echoes of input secrets are redacted;',
|
|
133
144
|
' do not treat redaction as protection against arbitrary transformations by an untrusted destination.',
|
|
134
|
-
' Optional save: "<name>"
|
|
145
|
+
' Optional save: "<name>" keeps the response body as a given grant and returns only status/headers and saved metadata.',
|
|
135
146
|
' Redirects are returned, not followed.',
|
|
136
147
|
' HTTPS on 443, public hostnames only, never this server or private networks. 1MB each way, 20 seconds, 30/minute.',
|
|
137
148
|
' No workflow, schedule or implicit execution: the caller chooses each invocation and each saved output.', '',
|
|
@@ -151,7 +162,7 @@ export function guide(connectors) {
|
|
|
151
162
|
' Use this instead of POST /v1/deliveries whenever the point is to run something.',
|
|
152
163
|
` foundation exec --output '{"name":"login config","as":"AUTH_FILE","filename":"auth.json"}' -- <command>`,
|
|
153
164
|
' Creates one empty private file and sets as to its path. Tell the command to write its authentication result there.',
|
|
154
|
-
' After exit 0,
|
|
165
|
+
' After exit 0, keeps the file bytes as a given grant under the exact name, then removes the temporary file.',
|
|
155
166
|
' An existing value at that name is replaced. Output must be a private regular file containing 1 byte to 1MB.',
|
|
156
167
|
' May be combined with inputs, using a different environment variable. A failed command never saves its output.',
|
|
157
168
|
' If upload cannot be confirmed, exits with an error and reports the retained private file for recovery; inputs are',
|
package/package.json
CHANGED
package/runtime.mjs
CHANGED
|
@@ -107,7 +107,7 @@ Commands:
|
|
|
107
107
|
Send one request to the Foundation API with the key attached.
|
|
108
108
|
exec <ENV>=<name> [...] -- <command> [args...]
|
|
109
109
|
Run a command with saved values in its environment.
|
|
110
|
-
exec --inputs '<json>' -- <command> The same, with files or
|
|
110
|
+
exec --inputs '<json>' -- <command> The same, with files, structured inputs, or a connected grant by id.
|
|
111
111
|
exec --output '<json>' -- <command> Also save a file the command writes.
|
|
112
112
|
guide The API guide: what Foundation keeps, and how to ask it for things.
|
|
113
113
|
version Print the version.
|
|
@@ -150,8 +150,10 @@ async function main() {
|
|
|
150
150
|
if (at < 1) throw new Error('Specify the environment variable explicitly: ENV=name');
|
|
151
151
|
return { name: value.slice(at + 1), as: value.slice(0, at) };
|
|
152
152
|
});
|
|
153
|
-
|
|
154
|
-
if (
|
|
153
|
+
// A connected grant names its own variables, so an input may leave `as` out; a given one must say where it goes.
|
|
154
|
+
if (!Array.isArray(names) || names.length > 16 || names.some(item => !item || typeof item.name !== 'string' || !item.name || (item.as !== undefined && !validEnvName(item.as)))) throw new Error('Each input needs a name and, when given, a non-reserved environment variable in as.');
|
|
155
|
+
const chosen = names.map(item => item.as).filter(value => value !== undefined);
|
|
156
|
+
if (new Set(chosen).size !== chosen.length) throw new Error('Each input needs a different environment variable.');
|
|
155
157
|
if (parsed.values.output !== undefined) {
|
|
156
158
|
try { output = JSON.parse(parsed.values.output); } catch { throw new Error('--output must be a JSON object {name, as, filename}.'); }
|
|
157
159
|
if (!output || Array.isArray(output) || typeof output !== 'object' || Object.keys(output).some(key => !['name', 'as', 'filename'].includes(key))) throw new Error('--output must be a JSON object {name, as, filename}.');
|
|
@@ -264,7 +266,7 @@ async function main() {
|
|
|
264
266
|
}
|
|
265
267
|
}
|
|
266
268
|
};
|
|
267
|
-
const recovery = () => 'Foundation could not confirm the output was saved. The private output file is retained for recovery: ' + outputPath + '\nRetry with foundation api PUT "/v1/holdings?kind=
|
|
269
|
+
const recovery = () => 'Foundation could not confirm the output was saved. The private output file is retained for recovery: ' + outputPath + '\nRetry with foundation api PUT "/v1/holdings?kind=grant&name=<URL-encoded-name>" --from <file>, then remove that recovery file.';
|
|
268
270
|
process.once('exit', cleanup);
|
|
269
271
|
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) process.once(signal, () => {
|
|
270
272
|
interrupted = true;
|
|
@@ -303,7 +305,7 @@ async function main() {
|
|
|
303
305
|
retainOutput = true;
|
|
304
306
|
// The command wrote it; the agent never saw it, and keeps it that way: the line drawn for the one who kept it is declined.
|
|
305
307
|
let saved;
|
|
306
|
-
try { saved = await send(forHolder('/v1/holdings?kind=
|
|
308
|
+
try { saved = await send(forHolder('/v1/holdings?kind=grant&name=' + encodeURIComponent(output.name)), bytes, { method: 'PUT', type: 'application/octet-stream' }); }
|
|
307
309
|
catch { throw new Error(recovery()); }
|
|
308
310
|
try { await send('/v1/relations', { relation: 'editor', object_type: 'holding', object_id: saved.holding.id }, { method: 'DELETE' }); } catch {}
|
|
309
311
|
retainOutput = false;
|