@pensar/apex 2.4.0 → 2.5.0-canary.22f2eb52
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/build/agent-7qtpem5z.js +12 -0
- package/build/agent-9khcyh5t.js +14 -0
- package/build/agent-bsyhck0a.js +12 -0
- package/build/{agent-5ejt5vpz.js → agent-ywewzc2h.js} +42 -42
- package/build/{apps-17wvz1d7.js → apps-11akynyv.js} +74 -43
- package/build/{auth-z3h9859n.js → auth-dd6r9mk4.js} +57 -61
- package/build/blackboxAgent-hbra4k00.js +12 -0
- package/build/blackboxPentest-bn5evs2z.js +61 -0
- package/build/{cli-xshasbwe.js → cli-3v9zs5wm.js} +31 -52
- package/build/{cli-mavved45.js → cli-4z46kyrk.js} +86 -93
- package/build/cli-7vby0hk6.js +12136 -0
- package/build/{cli-gq40s5b3.js → cli-8kkaeb70.js} +33 -46
- package/build/cli-8w8k4dph.js +15 -0
- package/build/cli-ag6jtndp.js +32 -0
- package/build/{cli-2cbwdk78.js → cli-ak78mweh.js} +4 -4
- package/build/cli-bb02pjt0.js +1485 -0
- package/build/{cli-k71t434r.js → cli-ec2hwkv3.js} +34 -76
- package/build/{cli-vnynf0js.js → cli-f5rw841m.js} +11 -5
- package/build/{cli-k8kc47pq.js → cli-gamfs2yq.js} +118 -115
- package/build/{cli-32z0017y.js → cli-gq5sk2j3.js} +36 -60
- package/build/{cli-bc05qbss.js → cli-h6y3bt60.js} +13 -21
- package/build/{cli-tkc598ey.js → cli-j1916nvj.js} +10035 -7661
- package/build/{cli-5k33webc.js → cli-jw1xftqm.js} +355 -332
- package/build/{cli-tznv8pf1.js → cli-n4h7ygp5.js} +4 -4
- package/build/{cli-b1adytsy.js → cli-q45hcq3f.js} +67 -39
- package/build/{cli-repbyhkk.js → cli-qkb3v2nw.js} +26063 -25373
- package/build/{cli-j54qa6tm.js → cli-qktcyj48.js} +1 -1
- package/build/cli-retw3rw5.js +12 -0
- package/build/cli-tjm77pmx.js +12075 -0
- package/build/{cli-dm0fc0bm.js → cli-v1sarr4y.js} +5 -9
- package/build/{cli-9rhzhgx2.js → cli-v8ph8hy2.js} +5 -5
- package/build/{cli-vq52kp7j.js → cli-vkxx4jzv.js} +147 -128
- package/build/cli-wfb4gde1.js +22 -0
- package/build/{cli-ee3axgts.js → cli-xbhr5khz.js} +1 -1
- package/build/cli-z82n3qk1.js +6 -0
- package/build/cli.js +689 -132
- package/build/{config-f1mj4nhd.js → config-kv5v9ctn.js} +29 -29
- package/build/{doctor-ekneewa3.js → doctor-xs4s5km8.js} +4 -9
- package/build/{fastStrike-8zka43xs.js → fastStrike-b8t8f916.js} +26 -28
- package/build/{fixes-b89s5haw.js → fixes-kcckqx3s.js} +22 -27
- package/build/getMachineId-bsd-zr67nd9p.js +36 -0
- package/build/getMachineId-darwin-fd1d562d.js +36 -0
- package/build/getMachineId-linux-kjmg243j.js +29 -0
- package/build/getMachineId-unsupported-n4r58vke.js +19 -0
- package/build/getMachineId-win-yzgpfsrb.js +38 -0
- package/build/index-3mzr07h0.js +9 -0
- package/build/index-63zf8jxx.js +12 -0
- package/build/index-a1bg29j1.js +1559 -0
- package/build/{index-cbwn03kz.js → index-a2xycbjs.js} +12 -31
- package/build/{index-6d22pyxt.js → index-ae81pvwg.js} +2995 -2432
- package/build/index-cbajq2xy.js +17 -0
- package/build/index-cn4p95gh.js +100 -0
- package/build/index-kas88svr.js +36 -0
- package/build/index-mr20g8k4.js +22 -0
- package/build/{index-psqjpw5m.js → index-nweqptgs.js} +7 -7
- package/build/{index-sf16jm0m.js → index-rx5jn1nz.js} +137 -162
- package/build/{issues-xx5bs4md.js → issues-jm28k288.js} +81 -35
- package/build/{logs-qtxe51w2.js → logs-r02tbz89.js} +20 -25
- package/build/{multipart-parser-g2xxkezz.js → multipart-parser-vjjdbpd1.js} +10 -10
- package/build/{offesecAgent-b9e2xm6v.js → offesecAgent-mmfejh1j.js} +6 -13
- package/build/{parse-rtccymzn.js → parse-cqecqrc5.js} +0 -4
- package/build/pentest-13jcm4cy.js +21 -0
- package/build/{pentests-6ks3szc4.js → pentests-jyn4zs7n.js} +23 -28
- package/build/{targetedPentest-s1ptvq8e.js → targetedPentest-m3qkbpv6.js} +16 -20
- package/build/{targets-sxygyj87.js → targets-rqv57as0.js} +22 -27
- package/build/threatModel-scmz36xr.js +19 -0
- package/build/{token-3bbp59y6.js → token-n0tmq8n5.js} +2 -2
- package/build/{token-util-6xjme11b.js → token-util-bv80pj47.js} +1 -2
- package/build/{uninstall-tvsh81v8.js → uninstall-bme62bdg.js} +7 -4
- package/build/{upload-7wdyyqmr.js → upload-hwpgx1ha.js} +7 -13
- package/build/{utils-7fwdkqk6.js → utils-abtz5mmk.js} +7 -29
- package/package.json +8 -2
- package/build/agent-mvpgvgks.js +0 -19
- package/build/agent-nhs1w5w0.js +0 -29
- package/build/authentication-3s97cpk4.js +0 -19
- package/build/blackboxAgent-gw0a1ca4.js +0 -19
- package/build/blackboxPentest-44333zss.js +0 -37
- package/build/cli-0n4r54hq.js +0 -414
- package/build/cli-72cvcqhg.js +0 -22
- package/build/cli-qqt4gj1w.js +0 -53
- package/build/cli-swpbx60z.js +0 -24441
- package/build/index-4ad3sdwk.js +0 -39
- package/build/index-ghwf5z3v.js +0 -12
- package/build/index-hqjdg6fg.js +0 -205
- package/build/index-mtq7kmxz.js +0 -12856
- package/build/index-rbzhk712.js +0 -33
- package/build/index-y5w6n3tb.js +0 -19
- package/build/main-mmjp338j.js +0 -324
- package/build/pentest-xtc1sjdw.js +0 -29
- package/build/threatModel-xsm6fwk5.js +0 -27
- /package/build/{cli-c8131c4q.js → cli-0wsh8j2t.js} +0 -0
- /package/build/{cli-e08r86zk.js → cli-b3dvxjgk.js} +0 -0
- /package/build/{cli-fw5r7pfj.js → cli-q126f6ef.js} +0 -0
- /package/build/{cli-9fsre5pt.js → cli-qba2x69h.js} +0 -0
|
@@ -1,15 +1,10 @@
|
|
|
1
|
+
import"./cli-wfb4gde1.js";
|
|
2
|
+
import"./cli-j1916nvj.js";
|
|
1
3
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./cli-
|
|
5
|
-
import"./cli-
|
|
6
|
-
import"./cli-0n4r54hq.js";
|
|
7
|
-
import"./cli-swpbx60z.js";
|
|
8
|
-
import"./cli-j54qa6tm.js";
|
|
9
|
-
import"./cli-72cvcqhg.js";
|
|
10
|
-
import"./cli-9rhzhgx2.js";
|
|
11
|
-
import"./cli-vnynf0js.js";
|
|
12
|
-
import"./cli-bc05qbss.js";
|
|
4
|
+
resolveConfig,
|
|
5
|
+
createWeaveTracer
|
|
6
|
+
} from "./cli-ak78mweh.js";
|
|
7
|
+
import"./cli-qktcyj48.js";
|
|
13
8
|
|
|
14
9
|
// src/core/integrations/wandb/upload.ts
|
|
15
10
|
async function createWandbUploader(session, opts) {
|
|
@@ -38,6 +33,5 @@ async function attachWandbToEventBus(session, eventBus, opts) {
|
|
|
38
33
|
};
|
|
39
34
|
}
|
|
40
35
|
export {
|
|
41
|
-
attachWandbToEventBus
|
|
42
|
-
createWandbUploader
|
|
36
|
+
attachWandbToEventBus
|
|
43
37
|
};
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
AVAILABLE_PROVIDERS,
|
|
3
|
-
init_types
|
|
4
|
-
} from "./cli-ee3axgts.js";
|
|
1
|
+
import"./cli-wfb4gde1.js";
|
|
5
2
|
import {
|
|
6
3
|
AVAILABLE_MODELS,
|
|
7
4
|
init_ai
|
|
8
|
-
} from "./cli-
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import"./cli-
|
|
13
|
-
import"./cli-9rhzhgx2.js";
|
|
14
|
-
import"./cli-vnynf0js.js";
|
|
15
|
-
import"./cli-bc05qbss.js";
|
|
5
|
+
} from "./cli-j1916nvj.js";
|
|
6
|
+
import {
|
|
7
|
+
init_types
|
|
8
|
+
} from "./cli-xbhr5khz.js";
|
|
9
|
+
import"./cli-qktcyj48.js";
|
|
16
10
|
|
|
17
11
|
// src/core/providers/utils.ts
|
|
18
12
|
init_ai();
|
|
@@ -35,16 +29,6 @@ var PREFERRED_MODEL_BY_PROVIDER = {
|
|
|
35
29
|
concentrate: "concentrate:claude-opus-4-6",
|
|
36
30
|
bedrock: "anthropic.claude-opus-4-6-v1"
|
|
37
31
|
};
|
|
38
|
-
function getConfiguredProviders(config) {
|
|
39
|
-
return AVAILABLE_PROVIDERS.map((provider) => {
|
|
40
|
-
const configured = isProviderConfigured(provider.id, config);
|
|
41
|
-
return {
|
|
42
|
-
...provider,
|
|
43
|
-
configured,
|
|
44
|
-
hasValidKey: configured
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
32
|
function isProviderConfigured(providerId, config) {
|
|
49
33
|
switch (providerId) {
|
|
50
34
|
case "anthropic":
|
|
@@ -69,9 +53,6 @@ function isProviderConfigured(providerId, config) {
|
|
|
69
53
|
return false;
|
|
70
54
|
}
|
|
71
55
|
}
|
|
72
|
-
function hasAnyProviderConfigured(config) {
|
|
73
|
-
return !!config.anthropicAPIKey || !!config.openAiAPIKey || !!config.googleAPIKey || !!config.openRouterAPIKey || !!config.concentrateAPIKey || !!config.inceptionAPIKey || !!config.bedrockAPIKey || !!config.localModelUrl || !!config.localModelName || !!process.env.LOCAL_MODEL_URL || !!config.pensarAPIKey || !!config.accessToken;
|
|
74
|
-
}
|
|
75
56
|
function getAvailableModels(config) {
|
|
76
57
|
const models = AVAILABLE_MODELS.filter((model) => {
|
|
77
58
|
return isProviderConfigured(model.provider, config);
|
|
@@ -110,8 +91,5 @@ function getDefaultModelForConfig(config) {
|
|
|
110
91
|
return available[0] ?? null;
|
|
111
92
|
}
|
|
112
93
|
export {
|
|
113
|
-
|
|
114
|
-
getConfiguredProviders,
|
|
115
|
-
getDefaultModelForConfig,
|
|
116
|
-
hasAnyProviderConfigured
|
|
94
|
+
getDefaultModelForConfig
|
|
117
95
|
};
|
package/package.json
CHANGED
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
17
17
|
"@openrouter/ai-sdk-provider": "^2.9.1",
|
|
18
18
|
"@opentelemetry/api": "^1.9.1",
|
|
19
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.221.0",
|
|
20
|
+
"@opentelemetry/otlp-exporter-base": "^0.221.0",
|
|
21
|
+
"@opentelemetry/otlp-transformer": "^0.221.0",
|
|
22
|
+
"@opentelemetry/resources": "^2.10.0",
|
|
19
23
|
"@opentui/core": "^0.1.107",
|
|
20
24
|
"@opentui/react": "^0.1.107",
|
|
21
25
|
"@pensar/surface": "0.3.0",
|
|
@@ -39,6 +43,8 @@
|
|
|
39
43
|
"description": "AI-powered penetration testing CLI tool with terminal UI",
|
|
40
44
|
"devDependencies": {
|
|
41
45
|
"@biomejs/biome": "2.4.14",
|
|
46
|
+
"@opentelemetry/context-async-hooks": "^2.10.0",
|
|
47
|
+
"@opentelemetry/sdk-trace-base": "^2.10.0",
|
|
42
48
|
"@types/bun": "^1.3.14",
|
|
43
49
|
"@types/mailparser": "^3.4.6",
|
|
44
50
|
"@types/mime-types": "^3.0.1",
|
|
@@ -85,7 +91,7 @@
|
|
|
85
91
|
"url": "https://github.com/pensarai/apex.git"
|
|
86
92
|
},
|
|
87
93
|
"scripts": {
|
|
88
|
-
"build": "bun build src/cli.ts --outdir build --target node --format esm --splitting --external @opentui/core --external @opentui/react --external @opentui/react/* --external react --external react/jsx-runtime --external react/jsx-dev-runtime --external react-reconciler --external weave --external electron --external chromium-bidi --external camoufox-js",
|
|
94
|
+
"build": "rm -rf build && bun build src/cli.ts --outdir build --target node --format esm --splitting --external @opentui/core --external @opentui/react --external @opentui/react/* --external react --external react/jsx-runtime --external react/jsx-dev-runtime --external react-reconciler --external weave --external electron --external chromium-bidi --external camoufox-js",
|
|
89
95
|
"build:binaries": "bun run generate:ascii && mkdir -p dist && bun run build:binary:macos-arm64 && bun run build:binary:macos-x64 && bun run build:binary:linux-x64 && bun run build:binary:linux-arm64",
|
|
90
96
|
"build:binary": "bun run generate:ascii && bun build src/cli.ts --compile --external electron --external chromium-bidi --external camoufox-js --outfile pensar",
|
|
91
97
|
"build:binary:linux-arm64": "bun build src/cli.ts --compile --external electron --external chromium-bidi --external camoufox-js --target=bun-linux-arm64 --outfile dist/pensar-linux-arm64",
|
|
@@ -113,5 +119,5 @@
|
|
|
113
119
|
"tsc": "tsc --noEmit"
|
|
114
120
|
},
|
|
115
121
|
"type": "module",
|
|
116
|
-
"version": "2.
|
|
122
|
+
"version": "2.5.0-canary.22f2eb52"
|
|
117
123
|
}
|
package/build/agent-mvpgvgks.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CodeAgent
|
|
3
|
-
} from "./cli-32z0017y.js";
|
|
4
|
-
import"./cli-9fsre5pt.js";
|
|
5
|
-
import"./cli-qqt4gj1w.js";
|
|
6
|
-
import"./cli-repbyhkk.js";
|
|
7
|
-
import"./cli-tznv8pf1.js";
|
|
8
|
-
import"./cli-c8131c4q.js";
|
|
9
|
-
import"./cli-tkc598ey.js";
|
|
10
|
-
import"./cli-0n4r54hq.js";
|
|
11
|
-
import"./cli-swpbx60z.js";
|
|
12
|
-
import"./cli-j54qa6tm.js";
|
|
13
|
-
import"./cli-72cvcqhg.js";
|
|
14
|
-
import"./cli-9rhzhgx2.js";
|
|
15
|
-
import"./cli-vnynf0js.js";
|
|
16
|
-
import"./cli-bc05qbss.js";
|
|
17
|
-
export {
|
|
18
|
-
CodeAgent
|
|
19
|
-
};
|
package/build/agent-nhs1w5w0.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PentestResponseSchema,
|
|
3
|
-
TargetedPentestAgent,
|
|
4
|
-
buildPentestActiveTools,
|
|
5
|
-
buildPentestPrompt,
|
|
6
|
-
buildPentestSystemPrompt,
|
|
7
|
-
resolvePentestAgentRole
|
|
8
|
-
} from "./cli-mavved45.js";
|
|
9
|
-
import"./cli-9fsre5pt.js";
|
|
10
|
-
import"./cli-qqt4gj1w.js";
|
|
11
|
-
import"./cli-repbyhkk.js";
|
|
12
|
-
import"./cli-tznv8pf1.js";
|
|
13
|
-
import"./cli-c8131c4q.js";
|
|
14
|
-
import"./cli-tkc598ey.js";
|
|
15
|
-
import"./cli-0n4r54hq.js";
|
|
16
|
-
import"./cli-swpbx60z.js";
|
|
17
|
-
import"./cli-j54qa6tm.js";
|
|
18
|
-
import"./cli-72cvcqhg.js";
|
|
19
|
-
import"./cli-9rhzhgx2.js";
|
|
20
|
-
import"./cli-vnynf0js.js";
|
|
21
|
-
import"./cli-bc05qbss.js";
|
|
22
|
-
export {
|
|
23
|
-
PentestResponseSchema,
|
|
24
|
-
TargetedPentestAgent,
|
|
25
|
-
buildPentestActiveTools,
|
|
26
|
-
buildPentestPrompt,
|
|
27
|
-
buildPentestSystemPrompt,
|
|
28
|
-
resolvePentestAgentRole
|
|
29
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
runAuthenticationAgent
|
|
3
|
-
} from "./cli-xshasbwe.js";
|
|
4
|
-
import"./cli-9fsre5pt.js";
|
|
5
|
-
import"./cli-qqt4gj1w.js";
|
|
6
|
-
import"./cli-repbyhkk.js";
|
|
7
|
-
import"./cli-tznv8pf1.js";
|
|
8
|
-
import"./cli-c8131c4q.js";
|
|
9
|
-
import"./cli-tkc598ey.js";
|
|
10
|
-
import"./cli-0n4r54hq.js";
|
|
11
|
-
import"./cli-swpbx60z.js";
|
|
12
|
-
import"./cli-j54qa6tm.js";
|
|
13
|
-
import"./cli-72cvcqhg.js";
|
|
14
|
-
import"./cli-9rhzhgx2.js";
|
|
15
|
-
import"./cli-vnynf0js.js";
|
|
16
|
-
import"./cli-bc05qbss.js";
|
|
17
|
-
export {
|
|
18
|
-
runAuthenticationAgent
|
|
19
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BlackboxAttackSurfaceAgent
|
|
3
|
-
} from "./cli-gq40s5b3.js";
|
|
4
|
-
import"./cli-9fsre5pt.js";
|
|
5
|
-
import"./cli-qqt4gj1w.js";
|
|
6
|
-
import"./cli-repbyhkk.js";
|
|
7
|
-
import"./cli-tznv8pf1.js";
|
|
8
|
-
import"./cli-c8131c4q.js";
|
|
9
|
-
import"./cli-tkc598ey.js";
|
|
10
|
-
import"./cli-0n4r54hq.js";
|
|
11
|
-
import"./cli-swpbx60z.js";
|
|
12
|
-
import"./cli-j54qa6tm.js";
|
|
13
|
-
import"./cli-72cvcqhg.js";
|
|
14
|
-
import"./cli-9rhzhgx2.js";
|
|
15
|
-
import"./cli-vnynf0js.js";
|
|
16
|
-
import"./cli-bc05qbss.js";
|
|
17
|
-
export {
|
|
18
|
-
BlackboxAttackSurfaceAgent
|
|
19
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
runPentestWorkflow
|
|
3
|
-
} from "./cli-5k33webc.js";
|
|
4
|
-
import"./cli-gq40s5b3.js";
|
|
5
|
-
import"./cli-b1adytsy.js";
|
|
6
|
-
import"./cli-mavved45.js";
|
|
7
|
-
import"./cli-32z0017y.js";
|
|
8
|
-
import"./cli-k8kc47pq.js";
|
|
9
|
-
import"./cli-9fsre5pt.js";
|
|
10
|
-
import"./cli-qqt4gj1w.js";
|
|
11
|
-
import"./cli-repbyhkk.js";
|
|
12
|
-
import"./cli-tznv8pf1.js";
|
|
13
|
-
import"./cli-fw5r7pfj.js";
|
|
14
|
-
import"./cli-c8131c4q.js";
|
|
15
|
-
import"./cli-tkc598ey.js";
|
|
16
|
-
import"./cli-0n4r54hq.js";
|
|
17
|
-
import"./cli-swpbx60z.js";
|
|
18
|
-
import"./cli-j54qa6tm.js";
|
|
19
|
-
import"./cli-72cvcqhg.js";
|
|
20
|
-
import"./cli-9rhzhgx2.js";
|
|
21
|
-
import"./cli-vnynf0js.js";
|
|
22
|
-
import"./cli-bc05qbss.js";
|
|
23
|
-
|
|
24
|
-
// src/core/api/blackboxPentest.ts
|
|
25
|
-
async function runPentestAgent(input) {
|
|
26
|
-
const { findings, findingsPath, pocsPath, reportPath } = await runPentestWorkflow(input);
|
|
27
|
-
console.log(`
|
|
28
|
-
Found ${findings.length} vulnerabilities`);
|
|
29
|
-
console.log(`Findings: ${findingsPath}`);
|
|
30
|
-
console.log(`POCs: ${pocsPath}`);
|
|
31
|
-
if (reportPath)
|
|
32
|
-
console.log(`Report: ${reportPath}`);
|
|
33
|
-
return { findings, findingsPath, pocsPath, reportPath };
|
|
34
|
-
}
|
|
35
|
-
export {
|
|
36
|
-
runPentestAgent
|
|
37
|
-
};
|
package/build/cli-0n4r54hq.js
DELETED
|
@@ -1,414 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
config,
|
|
3
|
-
init_config
|
|
4
|
-
} from "./cli-72cvcqhg.js";
|
|
5
|
-
import {
|
|
6
|
-
__esm
|
|
7
|
-
} from "./cli-bc05qbss.js";
|
|
8
|
-
|
|
9
|
-
// src/core/auth/connection.ts
|
|
10
|
-
function isConnected(cfg) {
|
|
11
|
-
return !!(cfg.accessToken || cfg.pensarAPIKey);
|
|
12
|
-
}
|
|
13
|
-
async function disconnect() {
|
|
14
|
-
await config.update({
|
|
15
|
-
pensarAPIKey: null,
|
|
16
|
-
accessToken: null,
|
|
17
|
-
refreshToken: null,
|
|
18
|
-
workspaceId: null,
|
|
19
|
-
workspaceSlug: null,
|
|
20
|
-
gatewaySigningKey: null
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
var init_connection = __esm(() => {
|
|
24
|
-
init_config();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// src/core/api/constants.ts
|
|
28
|
-
function getPensarApiUrl() {
|
|
29
|
-
return process.env.PENSAR_API_URL || PENSAR_API_BASE_URL;
|
|
30
|
-
}
|
|
31
|
-
function getPensarGatewayUrl() {
|
|
32
|
-
return process.env.PENSAR_GATEWAY_URL || PENSAR_GATEWAY_BASE_URL;
|
|
33
|
-
}
|
|
34
|
-
function getPensarConsoleUrl() {
|
|
35
|
-
return process.env.PENSAR_CONSOLE_URL || PENSAR_CONSOLE_BASE_URL;
|
|
36
|
-
}
|
|
37
|
-
var PENSAR_API_BASE_URL = "https://api.pensar.dev", PENSAR_GATEWAY_BASE_URL = "https://gateway.pensar.dev", PENSAR_CONSOLE_BASE_URL = "https://console.pensar.dev";
|
|
38
|
-
var init_constants = () => {};
|
|
39
|
-
|
|
40
|
-
// src/core/auth/device-flow.ts
|
|
41
|
-
function sleep(ms) {
|
|
42
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
43
|
-
}
|
|
44
|
-
async function startDeviceFlow(apiUrl) {
|
|
45
|
-
const url = apiUrl ?? getPensarApiUrl();
|
|
46
|
-
let workosClientId;
|
|
47
|
-
try {
|
|
48
|
-
const configResponse = await fetch(`${url}/api/cli/config`);
|
|
49
|
-
if (configResponse.ok) {
|
|
50
|
-
const cliConfig = await configResponse.json();
|
|
51
|
-
workosClientId = cliConfig.workosClientId;
|
|
52
|
-
const response2 = await fetch("https://api.workos.com/user_management/authorize/device", {
|
|
53
|
-
method: "POST",
|
|
54
|
-
headers: { "Content-Type": "application/json" },
|
|
55
|
-
body: JSON.stringify({ client_id: cliConfig.workosClientId })
|
|
56
|
-
});
|
|
57
|
-
if (response2.ok) {
|
|
58
|
-
const deviceInfo2 = await response2.json();
|
|
59
|
-
return {
|
|
60
|
-
mode: "workos",
|
|
61
|
-
clientId: cliConfig.workosClientId,
|
|
62
|
-
deviceInfo: deviceInfo2
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
} catch {}
|
|
67
|
-
const response = await fetch(`${url}/auth/device/code`, {
|
|
68
|
-
method: "POST",
|
|
69
|
-
headers: { "Content-Type": "application/json" },
|
|
70
|
-
body: JSON.stringify(workosClientId ? { client_id: workosClientId } : {})
|
|
71
|
-
});
|
|
72
|
-
if (!response.ok) {
|
|
73
|
-
throw new Error("Failed to start device authorization");
|
|
74
|
-
}
|
|
75
|
-
const deviceInfo = await response.json();
|
|
76
|
-
return { mode: "legacy", clientId: workosClientId, deviceInfo };
|
|
77
|
-
}
|
|
78
|
-
async function pollWorkOSToken(params) {
|
|
79
|
-
const { clientId, deviceCode, interval, expiresIn, signal } = params;
|
|
80
|
-
const deadline = Date.now() + expiresIn * 1000;
|
|
81
|
-
while (Date.now() < deadline) {
|
|
82
|
-
if (signal?.aborted)
|
|
83
|
-
throw new Error("Authorization cancelled");
|
|
84
|
-
await sleep(interval * 1000);
|
|
85
|
-
if (signal?.aborted)
|
|
86
|
-
throw new Error("Authorization cancelled");
|
|
87
|
-
try {
|
|
88
|
-
const response = await fetch("https://api.workos.com/user_management/authenticate", {
|
|
89
|
-
method: "POST",
|
|
90
|
-
headers: { "Content-Type": "application/json" },
|
|
91
|
-
body: JSON.stringify({
|
|
92
|
-
client_id: clientId,
|
|
93
|
-
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
94
|
-
device_code: deviceCode
|
|
95
|
-
})
|
|
96
|
-
});
|
|
97
|
-
if (response.status === 400) {
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
if (!response.ok) {
|
|
101
|
-
throw new Error("Authentication failed");
|
|
102
|
-
}
|
|
103
|
-
const data = await response.json();
|
|
104
|
-
return {
|
|
105
|
-
accessToken: data.access_token,
|
|
106
|
-
refreshToken: data.refresh_token
|
|
107
|
-
};
|
|
108
|
-
} catch (err) {
|
|
109
|
-
if (err instanceof Error && (err.message === "Authentication failed" || err.message === "Authorization cancelled")) {
|
|
110
|
-
throw err;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
throw new Error("Authorization timed out. Please try again.");
|
|
115
|
-
}
|
|
116
|
-
async function pollLegacyToken(params) {
|
|
117
|
-
const { apiUrl, deviceCode, interval, expiresIn, clientId, signal } = params;
|
|
118
|
-
const deadline = Date.now() + expiresIn * 1000;
|
|
119
|
-
while (Date.now() < deadline) {
|
|
120
|
-
if (signal?.aborted)
|
|
121
|
-
throw new Error("Authorization cancelled");
|
|
122
|
-
await sleep(interval * 1000);
|
|
123
|
-
if (signal?.aborted)
|
|
124
|
-
throw new Error("Authorization cancelled");
|
|
125
|
-
try {
|
|
126
|
-
const response = await fetch(`${apiUrl}/auth/device/token`, {
|
|
127
|
-
method: "POST",
|
|
128
|
-
headers: { "Content-Type": "application/json" },
|
|
129
|
-
body: JSON.stringify(clientId ? { deviceCode, client_id: clientId } : { deviceCode })
|
|
130
|
-
});
|
|
131
|
-
if (!response.ok)
|
|
132
|
-
continue;
|
|
133
|
-
const data = await response.json();
|
|
134
|
-
if (data.status === "complete" && data.apiKey) {
|
|
135
|
-
return data;
|
|
136
|
-
}
|
|
137
|
-
if (data.status === "expired") {
|
|
138
|
-
throw new Error("Authorization expired. Please try again.");
|
|
139
|
-
}
|
|
140
|
-
if (data.status === "not_found") {
|
|
141
|
-
throw new Error("Invalid authorization session. Please try again.");
|
|
142
|
-
}
|
|
143
|
-
} catch (err) {
|
|
144
|
-
if (signal?.aborted) {
|
|
145
|
-
throw new Error("Authorization cancelled", { cause: err });
|
|
146
|
-
}
|
|
147
|
-
if (err instanceof Error && err.message.includes("Please try again")) {
|
|
148
|
-
throw err;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
throw new Error("Authorization timed out. Please try again.");
|
|
153
|
-
}
|
|
154
|
-
var init_device_flow = __esm(() => {
|
|
155
|
-
init_constants();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
// src/core/auth/token.ts
|
|
159
|
-
function decodeJwtPayload(token) {
|
|
160
|
-
try {
|
|
161
|
-
const parts = token.split(".");
|
|
162
|
-
if (parts.length !== 3)
|
|
163
|
-
return null;
|
|
164
|
-
const payload = Buffer.from(parts[1], "base64url").toString("utf-8");
|
|
165
|
-
return JSON.parse(payload);
|
|
166
|
-
} catch {
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
function isTokenExpired(token, bufferSeconds = 60) {
|
|
171
|
-
const payload = decodeJwtPayload(token);
|
|
172
|
-
if (!payload || typeof payload.exp !== "number")
|
|
173
|
-
return true;
|
|
174
|
-
const nowSeconds = Math.floor(Date.now() / 1000);
|
|
175
|
-
return payload.exp - nowSeconds < bufferSeconds;
|
|
176
|
-
}
|
|
177
|
-
async function fetchWorkOSClientId() {
|
|
178
|
-
if (cachedClientId)
|
|
179
|
-
return cachedClientId;
|
|
180
|
-
try {
|
|
181
|
-
const apiUrl = getPensarApiUrl();
|
|
182
|
-
const response = await fetch(`${apiUrl}/api/cli/config`);
|
|
183
|
-
if (!response.ok)
|
|
184
|
-
return null;
|
|
185
|
-
const data = await response.json();
|
|
186
|
-
cachedClientId = data.workosClientId;
|
|
187
|
-
return cachedClientId;
|
|
188
|
-
} catch {
|
|
189
|
-
return null;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
async function refreshAccessToken(clientId, refreshToken) {
|
|
193
|
-
try {
|
|
194
|
-
const response = await fetch("https://api.workos.com/user_management/authenticate", {
|
|
195
|
-
method: "POST",
|
|
196
|
-
headers: { "Content-Type": "application/json" },
|
|
197
|
-
body: JSON.stringify({
|
|
198
|
-
client_id: clientId,
|
|
199
|
-
grant_type: "refresh_token",
|
|
200
|
-
refresh_token: refreshToken
|
|
201
|
-
})
|
|
202
|
-
});
|
|
203
|
-
if (!response.ok) {
|
|
204
|
-
console.error(`[pensar] Token refresh failed: ${response.status} ${response.statusText}`);
|
|
205
|
-
return null;
|
|
206
|
-
}
|
|
207
|
-
const data = await response.json();
|
|
208
|
-
await config.update({
|
|
209
|
-
accessToken: data.access_token,
|
|
210
|
-
refreshToken: data.refresh_token
|
|
211
|
-
});
|
|
212
|
-
return data.access_token;
|
|
213
|
-
} catch (err) {
|
|
214
|
-
console.error("[pensar] Token refresh error:", err);
|
|
215
|
-
return null;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
async function ensureValidToken(cfg) {
|
|
219
|
-
if (cfg.accessToken) {
|
|
220
|
-
if (!isTokenExpired(cfg.accessToken)) {
|
|
221
|
-
return { token: cfg.accessToken, type: "workos" };
|
|
222
|
-
}
|
|
223
|
-
if (cfg.refreshToken) {
|
|
224
|
-
const clientId = await fetchWorkOSClientId();
|
|
225
|
-
if (clientId) {
|
|
226
|
-
const newToken = await refreshAccessToken(clientId, cfg.refreshToken);
|
|
227
|
-
if (newToken) {
|
|
228
|
-
return { token: newToken, type: "workos" };
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (cfg.pensarAPIKey) {
|
|
234
|
-
return { token: cfg.pensarAPIKey, type: "legacy" };
|
|
235
|
-
}
|
|
236
|
-
return null;
|
|
237
|
-
}
|
|
238
|
-
var cachedClientId = null;
|
|
239
|
-
var init_token = __esm(() => {
|
|
240
|
-
init_constants();
|
|
241
|
-
init_config();
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
// src/core/auth/gateway.ts
|
|
245
|
-
async function validateGateway() {
|
|
246
|
-
const cfg = await config.get();
|
|
247
|
-
const tokenResult = await ensureValidToken({
|
|
248
|
-
accessToken: cfg.accessToken,
|
|
249
|
-
refreshToken: cfg.refreshToken,
|
|
250
|
-
pensarAPIKey: cfg.pensarAPIKey
|
|
251
|
-
});
|
|
252
|
-
if (!tokenResult)
|
|
253
|
-
return null;
|
|
254
|
-
const gatewayUrl = cfg.gatewayUrl || getPensarGatewayUrl();
|
|
255
|
-
const headers = {
|
|
256
|
-
Authorization: `Bearer ${tokenResult.token}`
|
|
257
|
-
};
|
|
258
|
-
if (cfg.workspaceId) {
|
|
259
|
-
headers["X-Workspace-Id"] = cfg.workspaceId;
|
|
260
|
-
}
|
|
261
|
-
const response = await fetch(`${gatewayUrl}/gateway/validate`, {
|
|
262
|
-
method: "GET",
|
|
263
|
-
headers
|
|
264
|
-
});
|
|
265
|
-
if (!response.ok) {
|
|
266
|
-
throw new Error(`Gateway validation failed (${response.status})`);
|
|
267
|
-
}
|
|
268
|
-
const result = await response.json();
|
|
269
|
-
if (result.signingKey || result.gatewayUrl) {
|
|
270
|
-
await config.update({
|
|
271
|
-
gatewaySigningKey: result.signingKey ?? undefined,
|
|
272
|
-
gatewayUrl: result.gatewayUrl ?? undefined
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
return result;
|
|
276
|
-
}
|
|
277
|
-
var init_gateway = __esm(() => {
|
|
278
|
-
init_constants();
|
|
279
|
-
init_config();
|
|
280
|
-
init_token();
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
// src/core/auth/signing.ts
|
|
284
|
-
import { createHash, createHmac, randomUUID } from "node:crypto";
|
|
285
|
-
function signGatewayRequest(signingKey, modelId, body) {
|
|
286
|
-
const timestamp = String(Math.floor(Date.now() / 1000));
|
|
287
|
-
const nonce = randomUUID();
|
|
288
|
-
const bodyHash = createHash("sha256").update(body).digest("hex");
|
|
289
|
-
const payload = `${timestamp}
|
|
290
|
-
${nonce}
|
|
291
|
-
${modelId}
|
|
292
|
-
${bodyHash}`;
|
|
293
|
-
const signature = createHmac("sha256", signingKey).update(payload).digest("base64");
|
|
294
|
-
return { signature, timestamp, nonce };
|
|
295
|
-
}
|
|
296
|
-
var init_signing = () => {};
|
|
297
|
-
|
|
298
|
-
// src/core/auth/workspaces.ts
|
|
299
|
-
function sleep2(ms) {
|
|
300
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
301
|
-
}
|
|
302
|
-
async function fetchWorkspaces(apiUrl, accessToken) {
|
|
303
|
-
const response = await fetch(`${apiUrl}/api/cli/workspaces`, {
|
|
304
|
-
headers: { Authorization: `Bearer ${accessToken}` }
|
|
305
|
-
});
|
|
306
|
-
if (!response.ok) {
|
|
307
|
-
throw new Error(`Failed to fetch workspaces (${response.status})`);
|
|
308
|
-
}
|
|
309
|
-
const data = await response.json();
|
|
310
|
-
return {
|
|
311
|
-
workspaces: data.workspaces,
|
|
312
|
-
consoleUrl: data.consoleUrl
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
async function pollForWorkspaceCreation(apiUrl, accessToken, signal) {
|
|
316
|
-
const POLL_INTERVAL = 3000;
|
|
317
|
-
const TIMEOUT = 5 * 60 * 1000;
|
|
318
|
-
const deadline = Date.now() + TIMEOUT;
|
|
319
|
-
while (Date.now() < deadline) {
|
|
320
|
-
if (signal?.aborted)
|
|
321
|
-
throw new Error("Cancelled");
|
|
322
|
-
await sleep2(POLL_INTERVAL);
|
|
323
|
-
if (signal?.aborted)
|
|
324
|
-
throw new Error("Cancelled");
|
|
325
|
-
try {
|
|
326
|
-
const response = await fetch(`${apiUrl}/api/cli/workspaces`, {
|
|
327
|
-
headers: { Authorization: `Bearer ${accessToken}` }
|
|
328
|
-
});
|
|
329
|
-
if (!response.ok)
|
|
330
|
-
continue;
|
|
331
|
-
const data = await response.json();
|
|
332
|
-
if (data.workspaces.length > 0) {
|
|
333
|
-
return data.workspaces;
|
|
334
|
-
}
|
|
335
|
-
} catch {}
|
|
336
|
-
}
|
|
337
|
-
throw new Error("Workspace creation timed out. Please try again.");
|
|
338
|
-
}
|
|
339
|
-
async function selectWorkspace(apiUrl, accessToken, workspaceId) {
|
|
340
|
-
const response = await fetch(`${apiUrl}/api/cli/select-workspace`, {
|
|
341
|
-
method: "POST",
|
|
342
|
-
headers: {
|
|
343
|
-
"Content-Type": "application/json",
|
|
344
|
-
Authorization: `Bearer ${accessToken}`
|
|
345
|
-
},
|
|
346
|
-
body: JSON.stringify({ workspaceId })
|
|
347
|
-
});
|
|
348
|
-
if (!response.ok) {
|
|
349
|
-
throw new Error("Failed to select workspace");
|
|
350
|
-
}
|
|
351
|
-
return await response.json();
|
|
352
|
-
}
|
|
353
|
-
async function createWorkspaceSelection(apiUrl, accessToken) {
|
|
354
|
-
const response = await fetch(`${apiUrl}/api/cli/workspace-selection`, {
|
|
355
|
-
method: "POST",
|
|
356
|
-
headers: {
|
|
357
|
-
"Content-Type": "application/json",
|
|
358
|
-
Authorization: `Bearer ${accessToken}`
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
if (!response.ok) {
|
|
362
|
-
throw new Error("Failed to start workspace selection");
|
|
363
|
-
}
|
|
364
|
-
return await response.json();
|
|
365
|
-
}
|
|
366
|
-
async function pollWorkspaceSelection(apiUrl, accessToken, selectionId, signal) {
|
|
367
|
-
const POLL_INTERVAL = 3000;
|
|
368
|
-
const TIMEOUT = 10 * 60 * 1000;
|
|
369
|
-
const deadline = Date.now() + TIMEOUT;
|
|
370
|
-
while (Date.now() < deadline) {
|
|
371
|
-
if (signal?.aborted)
|
|
372
|
-
throw new Error("Cancelled");
|
|
373
|
-
await sleep2(POLL_INTERVAL);
|
|
374
|
-
if (signal?.aborted)
|
|
375
|
-
throw new Error("Cancelled");
|
|
376
|
-
try {
|
|
377
|
-
const response = await fetch(`${apiUrl}/api/cli/workspace-selection?id=${encodeURIComponent(selectionId)}`, {
|
|
378
|
-
headers: { Authorization: `Bearer ${accessToken}` }
|
|
379
|
-
});
|
|
380
|
-
if (!response.ok)
|
|
381
|
-
continue;
|
|
382
|
-
const data = await response.json();
|
|
383
|
-
if (data.status === "complete" && data.workspaceId) {
|
|
384
|
-
return data.workspaceId;
|
|
385
|
-
}
|
|
386
|
-
if (data.status === "expired") {
|
|
387
|
-
throw new Error("Workspace selection expired. Please run `pensar login` again.");
|
|
388
|
-
}
|
|
389
|
-
} catch (err) {
|
|
390
|
-
if (signal?.aborted)
|
|
391
|
-
throw new Error("Cancelled");
|
|
392
|
-
if (err instanceof Error && err.message.includes("Please try again")) {
|
|
393
|
-
throw err;
|
|
394
|
-
}
|
|
395
|
-
if (err instanceof Error && err.message.includes("expired")) {
|
|
396
|
-
throw err;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
throw new Error("Workspace selection timed out. Please try again.");
|
|
401
|
-
}
|
|
402
|
-
var init_workspaces = () => {};
|
|
403
|
-
|
|
404
|
-
// src/core/auth/index.ts
|
|
405
|
-
var init_auth = __esm(() => {
|
|
406
|
-
init_connection();
|
|
407
|
-
init_device_flow();
|
|
408
|
-
init_gateway();
|
|
409
|
-
init_signing();
|
|
410
|
-
init_token();
|
|
411
|
-
init_workspaces();
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
export { getPensarApiUrl, getPensarGatewayUrl, getPensarConsoleUrl, init_constants, isConnected, disconnect, startDeviceFlow, pollWorkOSToken, pollLegacyToken, isTokenExpired, ensureValidToken, validateGateway, signGatewayRequest, fetchWorkspaces, pollForWorkspaceCreation, selectWorkspace, createWorkspaceSelection, pollWorkspaceSelection, init_auth };
|
package/build/cli-72cvcqhg.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
get,
|
|
3
|
-
init,
|
|
4
|
-
init_config,
|
|
5
|
-
update
|
|
6
|
-
} from "./cli-9rhzhgx2.js";
|
|
7
|
-
import {
|
|
8
|
-
__esm
|
|
9
|
-
} from "./cli-bc05qbss.js";
|
|
10
|
-
|
|
11
|
-
// src/core/config/index.ts
|
|
12
|
-
var config;
|
|
13
|
-
var init_config2 = __esm(() => {
|
|
14
|
-
init_config();
|
|
15
|
-
config = {
|
|
16
|
-
get,
|
|
17
|
-
init,
|
|
18
|
-
update
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
export { config, init_config2 as init_config };
|