agent-permission 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAE7G,UAAU,UAAU;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,KAAK,CAAC;CACrB;AAED,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,MAAM,EAAE,MAAM,CAAC;gBAEH,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK5C;AAED,wBAAsB,eAAe,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAetG;AAED,wBAAsB,qBAAqB,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,aAAa,EAAE,CAAA;CAAE,CAAC,CAexH;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAUnH"}
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAE7G,UAAU,UAAU;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,KAAK,CAAC;CACrB;AAED,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,MAAM,EAAE,MAAM,CAAC;gBAEH,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK5C;AAED,wBAAsB,eAAe,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAgBtG;AAED,wBAAsB,qBAAqB,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,aAAa,EAAE,CAAA;CAAE,CAAC,CAgBxH;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAWnH"}
package/dist/api.js CHANGED
@@ -10,7 +10,8 @@ export async function checkPermission(params, options) {
10
10
  if (!options.apiKey) {
11
11
  throw new AgentPermissionApiError(401, 'Missing API key. Set AGENT_PERMISSION_API_KEY or run `agent-permission config set api-key <key>`.');
12
12
  }
13
- const res = await options.fetch(`${trimSlash(options.apiUrl)}/v1/check`, {
13
+ const apiUrl = trimSlash(options.apiUrl);
14
+ const res = await fetchApi(apiUrl, '/v1/check', options.fetch, {
14
15
  method: 'POST',
15
16
  headers: {
16
17
  'Content-Type': 'application/json',
@@ -24,7 +25,8 @@ export async function batchCheckPermissions(batch, options) {
24
25
  if (!options.apiKey) {
25
26
  throw new AgentPermissionApiError(401, 'Missing API key. Set AGENT_PERMISSION_API_KEY or run `agent-permission config set api-key <key>`.');
26
27
  }
27
- const res = await options.fetch(`${trimSlash(options.apiUrl)}/v1/batch-check`, {
28
+ const apiUrl = trimSlash(options.apiUrl);
29
+ const res = await fetchApi(apiUrl, '/v1/batch-check', options.fetch, {
28
30
  method: 'POST',
29
31
  headers: {
30
32
  'Content-Type': 'application/json',
@@ -35,7 +37,8 @@ export async function batchCheckPermissions(batch, options) {
35
37
  return readResponse(res);
36
38
  }
37
39
  export async function verifyReceipt(receipt, options) {
38
- const res = await options.fetch(`${trimSlash(options.apiUrl)}/v1/verify-receipt`, {
40
+ const apiUrl = trimSlash(options.apiUrl);
41
+ const res = await fetchApi(apiUrl, '/v1/verify-receipt', options.fetch, {
39
42
  method: 'POST',
40
43
  headers: {
41
44
  'Content-Type': 'application/json',
@@ -44,6 +47,19 @@ export async function verifyReceipt(receipt, options) {
44
47
  });
45
48
  return readResponse(res);
46
49
  }
50
+ async function fetchApi(apiUrl, path, fetchImpl, init) {
51
+ try {
52
+ return await fetchImpl(`${apiUrl}${path}`, init);
53
+ }
54
+ catch (err) {
55
+ const detail = err instanceof Error && err.message ? ` (${err.message})` : '';
56
+ throw new AgentPermissionApiError(0, [
57
+ `Agent Permission API request failed before reaching the service${detail}.`,
58
+ `Check network access to ${apiUrl}.`,
59
+ 'In sandboxed agents, approve outbound network access and retry.',
60
+ ].join('\n'));
61
+ }
62
+ }
47
63
  async function readResponse(res) {
48
64
  const body = await res.json().catch(() => ({}));
49
65
  if (!res.ok) {
package/dist/cli.js CHANGED
@@ -18,15 +18,15 @@ export async function runCli(argv, runtime, io) {
18
18
  return 0;
19
19
  }
20
20
  if (command === 'check')
21
- return runCheck(rest, runtime, io);
21
+ return await runCheck(rest, runtime, io);
22
22
  if (command === 'batch')
23
- return runBatch(rest, runtime, io);
23
+ return await runBatch(rest, runtime, io);
24
24
  if (command === 'verify-receipt')
25
- return runVerify(rest, runtime, io);
25
+ return await runVerify(rest, runtime, io);
26
26
  if (command === 'install')
27
- return runInstall(rest, runtime, io);
27
+ return await runInstall(rest, runtime, io);
28
28
  if (command === 'config')
29
- return runConfig(rest, runtime, io);
29
+ return await runConfig(rest, runtime, io);
30
30
  io.stderr(`Unknown command: ${command}\n\n${helpText()}`);
31
31
  return 1;
32
32
  }
package/dist/format.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CheckResponse, VerifyReceiptResponse } from './types.js';
2
- export declare function decisionExitCode(decision: string): 2 | 0 | 3 | 1;
2
+ export declare function decisionExitCode(decision: string): 0 | 2 | 3 | 1;
3
3
  export declare function formatCheckHuman(result: CheckResponse): string;
4
4
  export declare function formatBatchHuman(results: CheckResponse[]): string;
5
5
  export declare function formatVerifyHuman(result: VerifyReceiptResponse): string;
package/dist/install.js CHANGED
@@ -214,18 +214,32 @@ async function checkPermission(params, options) {
214
214
  throw new Error('Missing API key. Set AGENT_PERMISSION_API_KEY or run \`node .agent-permission/agent-permission.mjs config set api-key <key>\`.');
215
215
  }
216
216
 
217
- const res = await fetch(\`\${trimSlash(options.apiUrl)}/v1/check\`, {
218
- method: 'POST',
219
- headers: {
220
- 'Content-Type': 'application/json',
221
- 'Authorization': \`Bearer \${options.apiKey}\`,
222
- },
223
- body: JSON.stringify(params),
224
- });
217
+ const apiUrl = trimSlash(options.apiUrl);
218
+ const res = await fetchApi(apiUrl, '/v1/check', {
219
+ method: 'POST',
220
+ headers: {
221
+ 'Content-Type': 'application/json',
222
+ 'Authorization': \`Bearer \${options.apiKey}\`,
223
+ },
224
+ body: JSON.stringify(params),
225
+ });
225
226
 
226
227
  return readResponse(res);
227
228
  }
228
229
 
230
+ async function fetchApi(apiUrl, path, init) {
231
+ try {
232
+ return await fetch(\`\${apiUrl}\${path}\`, init);
233
+ } catch (err) {
234
+ const detail = err instanceof Error && err.message ? \` (\${err.message})\` : '';
235
+ throw new Error([
236
+ \`Agent Permission API request failed before reaching the service\${detail}.\`,
237
+ \`Check network access to \${apiUrl}.\`,
238
+ 'In sandboxed agents, approve outbound network access and retry.',
239
+ ].join('\\n'));
240
+ }
241
+ }
242
+
229
243
  async function readResponse(res) {
230
244
  const body = await res.json().catch(() => ({}));
231
245
  if (!res.ok) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-permission",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Public CLI for Agent Permission checks and agent workspace installation.",
5
5
  "type": "module",
6
6
  "bin": "./dist/index.js",